Jump to content

send data to url from sql


kabar916

Recommended Posts

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 />";
}
?>
-------------------------------------

post-123326-0-41801000-1426459424_thumb.jpg

post-123326-0-42433900-1426459432_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/295268-send-data-to-url-from-sql/
Share on other sites

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.

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>

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>
 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.