shams Posted July 15, 2018 Share Posted July 15, 2018 My web pages are organized in two mysql tables, table category with two columns cat_id and category and table subcategory with three columns cat_id, subcategory and subcat2, i run this msyql query from terminal it is working: mysql> SELECT subcat2 from subcategory WHERE cat_id=1 AND subcategory=3; +--------------+ | subcat2 | +--------------+ | 001_003.html | +--------------+ 1 row in set (0.01 sec) Next, i execute the dd-mysqli.php it successfully get the sql query values from the drop down menu and parse to the chgoto.php and run this as well this is in the dd-mysqli.php: echo "<form method=post name=f1 action='chgoto.php'>"; to print the cat_id and subcategory, it is working, this is chgoto.php: <?php require 'config-mysqli.php'; //////// End of connecting to database //////// $cat=$_POST['cat']; $page=$_POST['subcat']; echo "$cat <br> $page"; ?> the reslut is shown here: 1 (is cat_id) 3 (is subcategory The problem is with the next php code, i want to add a sql query with two conditions in the chgoto.php to get the subcat2 value which is the url of html pages (as i run this mysql query in termianl in the begining of this post) but this is not working and there is only blank page in the output: <?php require 'config-mysqli.php'; //////// End of connecting to database //////// $cat=$_POST['cat']; $page=$_POST['subcat']; $result = mysqli_query($connection,'SELECT subcat2 from subcategory WHERE cat_id='.$cat.' AND subcategory='.$page.''); $row = mysqli_fetch_assoc($result); while($row = mysqli_fetch_assoc($result)){ $url = $row['subcat2']; echo $url; exit ; } $result->close(); $connection->close(); ?> I already enabled the php error log but no errors are reported for this query. Quote Link to comment Share on other sites More sharing options...
requinix Posted July 16, 2018 Share Posted July 16, 2018 Take a look at these two lines of code $row = mysqli_fetch_assoc($result); while($row = mysqli_fetch_assoc($result)){ and tell your rubber duck what they are doing. 2 Quote Link to comment Share on other sites More sharing options...
shams Posted July 16, 2018 Author Share Posted July 16, 2018 Thanks for the hint, i remove the line $row = mysqli_fetch_assoc($result); now it work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.