0

Hey all, my first post in this brilliant website, got a lot of ideas from here.
So I'm a student and currently we are learning a bit of php and right now I'm stuck.

I have a database with URL adresses, there is 3 fields, id, name and adress.
I have added 10 adresses in the database and I can show them on a website with no problem.

Now I want to show them in a combobox where they I can select any of the adresses, I have written some code but I dont think it can read from the database, the combobox is empty.
What am I doing wrong?

<select name="batch" onchange="submit();">
<option value="-1" >-- Select Adress --</option>
<?php
mysql_connect("localhost" , "root" , "");
mysql_select_db("persontb");
$sql="SELECT * FROM adresser ORDER BY namn ASC";
$result=log_mysql_query($sql);
while($item=mysql_fetch_assoc($result))
{
 echo '<option value="'.$item['id'].'" '.isSelected($item['id'],$batch).'>'.$item['namn'].'</option>';
}
?>
</select>
2
Contributors
6
Replies
9
Views
6 Years
Discussion Span
Last Post by Eneswar
0

Yea, thats supose to be $result=mysql_query($sql); I think....

But it still doesnt show me the URLs in the combobox..

0

This is what I have now, however there is a blank list, dont think it fetches the names from database...?

<select name="batch" onchange="submit();">
<option value="-1" >-- Select Adress --</option>
<?php
mysql_connect("localhost" , "root" , "");
mysql_select_db("persontb");
$sql="SELECT * FROM adresser ORDER BY namn ASC";
$result=mysql_query($sql);
while($item=mysql_fetch_assoc($result))
{
 echo '<option value="'.$item['id'].'" '.$item['namn'].'</option>';
}
?>
</select>
0

Try this to see if you get any errors:

<select name="batch" onchange="submit();">
<option value="-1" >-- Select Adress --</option>
<?php
mysql_connect('localhost' , 'root' , '') or die(mysql_error());
mysql_select_db('persontb') or die(mysql_error());
$sql = 'SELECT * FROM adresser ORDER BY namn ASC';
$result = mysql_query($sql) or die(mysql_error());
while ($item = mysql_fetch_assoc($result))
{
  echo '<option value="'.$item['id'].'" '.isSelected($item['id'],$batch).'>'.$item['namn'].'</option>';
}
?>
</select>

Edited by pritaeas: n/a

0

I got it working now, I had an tag error, missed a ending tag, final code:

<select name="batch" onchange="submit();">
<option value="-1" >-- Select Adress --</option>
<?php
mysql_connect("localhost" , "root" , "");
mysql_select_db("persontb");
$sql="SELECT * FROM adresser ORDER BY namn ASC";
$result=mysql_query($sql);
while($item=mysql_fetch_assoc($result))
{
 echo '<option value="'.$item['id'].'" >'.$item['namn'].'</option>';
}
?>
</select>

Now I need to figure out how to make the URLs open when I choose one of the names in a combobox...


Edit: How would I edit this line:

echo '<option value="'.$item['id'].'" >'.$item['namn'].'</option>';

to include "<a href="$e">" </a> or similar?

Edit 2:
$e is the row I used on a normal page I show the data:

$e = $row["urladresser"];

Edited by Eneswar: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.