richo89 Posted March 26, 2009 Share Posted March 26, 2009 Hey, I have a form where by the user enters a search criteria for example alfa romeo price from £2000. The code then picks up the data from mysql table and prints the results out. However I want to have a page where the user clicks more info for a particular car it carries the information across to a new page. My code: <?PHP session_start(); //Create variables to store data from .html file $_SESSION['searchmake'] = $_GET['searchmake']; $searchmake = $_SESSION['searchmake']; $_SESSION['searchmodel'] = $_GET['searchmodel']; $searchmodel = $_SESSION['searchmodel']; $_SESSION['searchpricemin'] = $_GET['searchpricemin']; $searchpricemin = $_SESSION['searchpricemin']; $_SESSION['searchpricemax'] = $_GET['searchpricemax']; $searchpricemax = $_SESSION['searchpricemax']; require "config.php"; // All database details will be included here $page_name="cmSearch.php"; // If you use this code with a different page ( or file ) name then change this @$column_name=$_GET['column_name']; // Read the column name from query string. $start=$_GET['start']; // To take care global variable if OFF if(!($start > 0)) { // This variable is set to zero for the first page $start = 0; } $eu = ($start - 0); $limit = 6; // No of records to be shown per page. $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; echo "Searching for ". $_SESSION['searchmake'] ; //retrieve data echo " Between £". $_SESSION['searchpricemin'] ; //retrieve data echo " and £". $_SESSION['searchpricemax'] ; //retrieve data /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $query2=" SELECT * FROM cars WHERE make LIKE '$searchmake' AND price BETWEEN '$searchpricemin' AND '$searchpricemax' ORDER BY price ASC"; $result2=mysql_query($query2); echo mysql_error(); $nume=mysql_num_rows($result2); ////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page/////////// $query=" SELECT * FROM cars WHERE make LIKE '$searchmake' AND price BETWEEN '$searchpricemin' AND '$searchpricemax' ORDER BY price ASC"; if(isset($column_name) and strlen($column_name)>0){ $query = $query . " order by $column_name"; } $query = $query. " limit $eu, $limit "; $result=mysql_query($query); echo mysql_error(); //////////////// Now we will display the returned records in side the rows of the table///////// while($noticia = mysql_fetch_array($result)) { if($bgcolor=='#ffffff'){$bgcolor='#ffffff';} else{$bgcolor='#ffffff';} echo "<table border=0 width=100%>"; echo "<tr >"; echo "<td align=left colspan=5 BGCOLOR=#F8F8F8 id='title'> <font face='Verdana' color='#A00000' size='3'> <center><b><u>Cars For Sale</center></b></u></font></td>"; echo "<tr >"; echo "<td align=left rowspan=3 bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'><img src='$noticia[picture]'</font></td>"; echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[make] $noticia[model]</font></td>"; echo "<tr >"; echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[Reg] reg - $noticia[colour] - $noticia[description] - $noticia[miles] miles</font></td>"; echo "<tr >"; echo "<td align=left colspan=3 bgcolor=$bgcolor id='title'> <font face='Verdana' color='red' size='3'><u>Price:£$noticia[price]</u></font></td>"; echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'><a href='blank.php'>More Info???</a></font></td>"; echo "</tr>"; } echo "</table>"; ////////////////////////////// End of displaying the table with records //////////////////////// /////////////// Start the buttom links with Prev and next link with page numbers ///////////////// echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0) { print "<a href='$page_name?start=$back&column_name=$column_name&searchmake=$searchmake&searchpricemin=$searchpricemin&searchpricemax=$searchpricemax'><font face='Verdana' size='2'>PREV</font></a>"; } //////////////// Let us display the page links at center. We will not display the current page as a link /////////// echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i&column_name=$column_name&searchmake=$searchmake&searchpricemin=$searchpricemin&searchpricemax=$searchpricemax'><font face='Verdana' size='2'>$l</font></a> "; } else { echo "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red $l=$l+1; } echo "</td><td align='right' width='30%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume) { print "<a href='$page_name?start=$next&column_name=$column_name&searchmake=$searchmake&searchpricemin=$searchpricemin&searchpricemax=$searchpricemax'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td></tr></table>"; ?> So as you can see I have a table printing results $noticia[make] $noticia[model] for example. Now how can I carry these results over to a new page when a user clicks more info? Any help greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/151209-php-variables/ Share on other sites More sharing options...
POG1 Posted March 26, 2009 Share Posted March 26, 2009 use the GET method to do it. Create a link inside the loop to something like file.php?car=idNumber on that page you can then search using $_GET['car'] or $_REQUEST['car'] Link to comment https://forums.phpfreaks.com/topic/151209-php-variables/#findComment-794337 Share on other sites More sharing options...
richo89 Posted March 26, 2009 Author Share Posted March 26, 2009 How do I make the results in my table a variable for me to GET. Because my results in the table I need to somehow transfer over to a new page with the information where they have clicked More Info. Link to comment https://forums.phpfreaks.com/topic/151209-php-variables/#findComment-794426 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.