Im no Php guru but here are some things you might wanna double check:
if ($_GET["cat"])
$_GET['cat']";
You used double quotes on first, single quotes on second
instead of $row["name"];, try $row[0], or $row[1], depending of the pos of the row
edit: okey, i got some help and its fixed now...
old code:
working code:Code:if ($_GET["cat"]) { $query = "select * from products where cat = $_GET['cat']"; $res = mysql_query ($query) or die (mysql_error()); echo "<table>"; while ($row = mysql_fetch_array($res)) { echo "<tr><td>"; echo $row["prodnr"]; echo "</td></tr>"; } mysql_free_result($res); echo "</table>"; }
Code:if ($_GET["cat"]) { $getcat = $_GET["cat"]; $query = "select * from products where cat = '" . $_GET['cat'] . "'"; $res = mysql_query ($query) or die (mysql_error()); echo "<table>"; while ($row = mysql_fetch_array($res)) { echo "<tr><td>"; echo $row["prodname"]; echo "</td></tr>"; } mysql_free_result($res); echo "</table>"; }
Last edited by mjz; February 8th, 2004 at 12:53.
Im no Php guru but here are some things you might wanna double check:
if ($_GET["cat"])
$_GET['cat']";
You used double quotes on first, single quotes on second
instead of $row["name"];, try $row[0], or $row[1], depending of the pos of the row
-W
yeah, but doube or single quote shouldn't make any difference in this case, and it doesn't, i've tried... and neither does using number instead of names... but thanks for looking at the code...
fundamentals of quotes:
-single quote -> enclose statement which contains no variables;
-double quote -> enclose statement which may contain variables;
-no quote -> let php interprets the statement itself
valid:
$string = "I saw my $_GET[buddy]";
$string = "I saw my ".$_GET['buddy'];
$string = "I saw my ".$_GET["buddy"];
invalid:
$string = "I saw my $_GET['buddy']"; --> leads to empty output
$string = "I saw my $_GET["buddy"]"; --> parsed error
bloodyveins = Official FWS Php Guru![]()
-W
for clerification single quotes in an unparsed string, double quotes is a parsed string. no quotes is either a boolean or numeric datatype
Something of purely no interest to anyone unless they care about miniscule seconds of parse time, using $_GET['var'] will parse faster than $_GET["var"]. PLUS, you press TWO LESS KEYS when typing the former.
what?? $row['name'] comes very highly preferred by yours truly over $row['0'], $row['1'], etc... much easier to organize and keep track of, especially if you are pulling info from a large number of rows.Originally posted by Wojtek
instead of $row["name"];, try $row[0], or $row[1], depending of the pos of the row
w3rd
yeah... agree...Something of purely no interest to anyone unless they care about miniscule seconds of parse time, using $_GET parse faster than $_GET["var"]. PLUS, you press TWO LESS KEYS when typing the former.![]()
Bookmarks