kabar916 Posted March 15, 2015 Share Posted March 15, 2015 i have to 2 pages: category1.php and category2.php. category1.php has a list of vehicle Makes that are pulled from a table in Microsoft sql database. I want to be able click on one of the makes (for example "honda") and i get sent to category2.php and it shows a list of all the vehicle Models for that Make. see attachement 1 and 2. I know how to show the list in each page, i just don't how to send the Make the user clicks on. Here is the code for category2.php where i wrote "honda, how can that be dynamically, so it inputs whatever the user clicks on. I hope my explanation of what i need makes sense. ----------------------------------- </head> <?php $query = "SELECT DISTINCT make FROM database_Plinkdata ORDER BY make"; $result = sqlsrv_query($conn, $query); if (!$result){ die("Database queryfailed"); } ?> <body> <div id="outerwrapper"> <div id="contentwrapper"> <div id="header"></div> <div id="sidebarleft"> <div> <h1><a href="category.php?make=honda"> <?php while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){ echo $row["make"]. "<br />"; } ?> ------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/295268-send-data-to-url-from-sql/ Share on other sites More sharing options...
requinix Posted March 16, 2015 Share Posted March 16, 2015 Well, you know how to get the make, and you know how to put things into URLs, so... do that. The next page uses $_GET to get the make and runs a query with it. How about giving that a shot? If you have problems, post your code and explain what's going wrong. Quote Link to comment https://forums.phpfreaks.com/topic/295268-send-data-to-url-from-sql/#findComment-1508176 Share on other sites More sharing options...
kabar916 Posted March 16, 2015 Author Share Posted March 16, 2015 well, if you notice the link area of html code i manually entered in "honda". i need that area to turn into the same value that is clicked. Quote Link to comment https://forums.phpfreaks.com/topic/295268-send-data-to-url-from-sql/#findComment-1508181 Share on other sites More sharing options...
kabar916 Posted March 16, 2015 Author Share Posted March 16, 2015 this is what i am talking about: a href="category.php?make=honda">. How do i make the honda area be the same as what is clicked by user. Quote Link to comment https://forums.phpfreaks.com/topic/295268-send-data-to-url-from-sql/#findComment-1508182 Share on other sites More sharing options...
requinix Posted March 16, 2015 Share Posted March 16, 2015 With the same mechanism you used to put the make into the table: echo it. ">Which is a guess, since the code you've posted doesn't quite match up with the description you gave. Quote Link to comment https://forums.phpfreaks.com/topic/295268-send-data-to-url-from-sql/#findComment-1508192 Share on other sites More sharing options...
kabar916 Posted March 16, 2015 Author Share Posted March 16, 2015 its still not work. here is the complete code <?php $serverName = "COMPLAPTOP2"; //serverName\instanceName $connectionInfo = array( "Database"=>"QualityParts", "UID"=>"sa", "PWD"=>"abc123"); $conn = sqlsrv_connect( $serverName, $connectionInfo); $make = $_POST['make']; ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style type="text/css"> #outerwrapper { margin: 0px auto; width: 80%; background: #000; padding: 0px; } #contentwrapper { width: 100%; overflow: auto; background: #F00; } #header { width: 900px; height: 150px; background: #0FF; } #sidebarleft { float: left; width: 150px; font-family: Arial, Helvetica, sans-serif; font-size: 8px; line-height: 23px; color: #333; background: #0CF; } #centercontent { float: right; width: 750%; background: #33C; } #footer { width: 100%; height: 350px; background: #0CC; clear: both; } </style> </head> <?php $query = "SELECT DISTINCT make FROM database_Plinkdata ORDER BY make"; $result = sqlsrv_query($conn, $query); if (!$result){ die("Database queryfailed"); } ?> <body> <div id="outerwrapper"> <div id="contentwrapper"> <div id="header"></div> <div id="sidebarleft"> <div> <h1><a href="category.php?make=<?php echo $row["make"]; ?>"> <?php while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){ echo $row["make"]. "<br />"; } ?> </a></h1> </div> </div> <div id="centercontent"> </div> <div id="footer"></div> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/295268-send-data-to-url-from-sql/#findComment-1508193 Share on other sites More sharing options...
NotionCommotion Posted March 16, 2015 Share Posted March 16, 2015 URLs populate the $_GET supervariable, not the $_POST. Mess around with the following script to see what is going on. <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>get and post</title> </head> <body> <a href="?id=Honda">Honda</a> <a href="?id=Ford&model=Mustang">Ford</a> <a href="?id=123">Another car, and you might want to consider using a PK instead of model</a> <form method="post"> <input type="text" name="my_post"> <input type="submit" value="submit"> </form> <h1>$_GET</h1> <?php echo('<pre>'.print_r($_GET,1).'</pre>'); ?> <h1>$_POST</h1> <?php echo('<pre>'.print_r($_POST,1).'</pre>'); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/295268-send-data-to-url-from-sql/#findComment-1508206 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.