2 dimension array and listbox

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
galligraph
Forum Newbie
Posts: 11
Joined: Wed Dec 21, 2005 10:26 am

2 dimension array and listbox

Post by galligraph »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


My broblem is that i need 2 select 2 values from the table(Id, Category). How 2 put these 2 dimension array and then show these in the listbox. Here's what i made and it aint workin'. No error messages, but i know somethin' is wrong. I've  tried 2 long...

Code: Select all

$sql_lauseke = ("select Id, Category from Categoria");
     
	
    if  (!$sql_lauseke = mysql_query($sql_lauseke, $yhteys))

	{
	echo "Haku epaonnistui";
	echo mysql_error();
 	exit;
	}
      
    else
	{
	$row = array(Id, Category);
	
	}

	echo "<form action='index.php?id=' method='post'>";
	echo "<table width='400' border='0'>";

    echo "<tr><td>Kategoria:</td>
 		<td><select size=''name='kategoria'>"; for($i=0;$i<count($row);$i++){
    echo "<option value='".$row[$i][0]."'>".$row[$i][1];}"</option> ";
    echo "</select>"; "<td> </tr>";
Please help me.. :wink:


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

$sql_lauseke = ("select Id, Category from Categoria");
why do you have parentheses around that? might need to put ` back ticks around ID..can't remember if that's a reserved word or not...try that..
galligraph
Forum Newbie
Posts: 11
Joined: Wed Dec 21, 2005 10:26 am

Post by galligraph »

Didn't help @all! So if someone could help me it would be great. Yup I'll use those code tags next time...
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Well... the language isn't helping...

What is the display when there's no error message?

This code:

Code: Select all

$row = array(Id, Category);
Also looks suspicious: you're calling constants... intentional?

The whole logic of the thing is kinda whacked out...
galligraph
Forum Newbie
Posts: 11
Joined: Wed Dec 21, 2005 10:26 am

Post by galligraph »

"The whole logic of the thing is kinda whacked out..." :) That's why i'm here...

So my main problem is that i don't still know how to build up 2 dimensional array and put these 2 values(Id, Category) there. After that the for sentense should show those in the list box... The for-sentense should be aight.
User avatar
trukfixer
Forum Contributor
Posts: 174
Joined: Fri May 21, 2004 3:14 pm
Location: Miami, Florida, USA

Post by trukfixer »

Code: Select all

echo "<form action='index.php?id=' method='post'>";
    echo "<table width='400' border='0'>";

    echo "<tr><td>Kategoria:</td> <td><select size=''name='kategoria'>";
$sql_lauseke = "select Id, Category from Categoria"; 
$res = mysql_query($sql_lauseke,$yhteys);
$err = mysql_error();
$row = array();
if(empty($err)
{
       while($row = mysql_fetch_array($res))
       {
              echo "<option value='".$row['Id']."'>".$row['Category']."</option> ";
       }
}
else
{
echo "</select> <font color='red'>$err</font>";
}
    echo "</select>"; "<td> </tr>";
for example .. there's probably a few better ways to optimize this I imagine.. :)
galligraph
Forum Newbie
Posts: 11
Joined: Wed Dec 21, 2005 10:26 am

Post by galligraph »

Thanks a lot trukfixer and other ppl 2 :wink: Next time I can make it by myself :D
Post Reply