query is nor working

Hi, so i have this function where variable $mok is taken from another php file by submitting a form. I echoed $mok and it gets the right string, but it does not work in a query, because function does not show any rows. i know that something wrong is with a query but dont know what, maybe you guys can see what is wrong?

[php]function kat_mokykla(){
$mok=$_POST[‘mok’];
$q = mysql_query(“SELECT * FROM URL WHERE kategorija=’$mok’”) or die(mysql_error());
//header(“Location: test2.php”);
$num_rows = mysql_num_rows($q);
for($i=0; $i<$num_rows; $i++){
$url = mysql_result($q,$i,“url”);
echo “<a href=”$url">$url\n";
echo “
”;
}
}[/php]

the query seems to be correct however the way you display your data i dont think is right

here is how i would have done it

[php]

<?php function kat_mokykla() { $mok=$_POST['mok']; $q = mysql_query("SELECT * FROM URL WHERE kategorija='$mok'") or die(mysql_error()); //header("Location: test2.php"); if (mysql_num_rows($q)) { while($rows = mysql_fetch_assoc($q)) { echo ""; echo "
"; } } } ?>

[/php]

doing your way i get
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in line

[php]echo “<a href=”$rows[‘url’]">";[/php]

see which of these work

[php]

echo “”;

OR

echo “<a href=”{$rows[‘url’]}">";

OR

echo “<a href=’{$rows[‘url’]}’>”;
[/php]

sorry my mistake

[php]

<?php function kat_mokykla() { $mok=$_POST['mok']; $q = mysql_query("SELECT * FROM URL WHERE kategorija='$mok'") or die(mysql_error()); //header("Location: test2.php"); if (mysql_num_rows($q) > 0) { while($rows = mysql_fetch_assoc($q)) { echo ""; //if you get error here try replacing with one of my other options see my previos post echo "
"; } } } ?>

[/php]

now i doesn’t get an error, but it stays the same as it was with my way, white screen, doesn’t show any rows :confused:

it seems that query does not get any row results, but i dont understand why

umm show me your database table structure or let me help you thru teamviewer and skype

http://imageshack.us/photo/my-images/33/tablejd.png/
this is my database , it’s very simple
http://stud.if.ktu.lt/~artbuto/test2.php
and this is my page, when you press “mokyklos” it should submit “# kiti” and compare with column “kategorija”

p.s sorry for putting links like this, forum doesnt let hyperlink them

i see 10 pages containing a list of URL

is that what im suposed to see if not then for me works

you supposed to see that, but try to press mokyklos , and you will get an error

yeah i see

jo Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/artbuto/public_html/kategorijos.php on line 14

so i think that query is wrong, but i dont understand why, “# kiti” is submitted good, it shows when i echo it in a function :confused:

i sent u personal message so you add me on skype and work this out

thank you for your help and time wilson!!

your welcome.

mark this thread solved

Sponsor our Newsletter | Privacy Policy | Terms of Service