Page 1 of 1

2 dimension array and listbox

Posted: Wed Dec 21, 2005 11:21 am
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]

Posted: Wed Dec 21, 2005 11:31 am
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..

Posted: Wed Dec 21, 2005 2:31 pm
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...

Posted: Wed Dec 21, 2005 4:52 pm
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...

Posted: Thu Dec 22, 2005 3:23 am
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.

Posted: Thu Dec 22, 2005 9:26 am
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.. :)

Posted: Fri Dec 23, 2005 4:00 am
by galligraph
Thanks a lot trukfixer and other ppl 2 :wink: Next time I can make it by myself :D