zimmer Posted December 8, 2007 Share Posted December 8, 2007 I am using mySQL version version 5.0. I am trying to get a query to populate the information to a new page called results.php I do not know what I am doing but here is what I have so far...and it is still a work in progress so ANY tips are appreciated. I am using a slightly modified version of the query.php i posted here before. I am simply using the search button and nothing more. query.php <head><body> <table width="393" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="form1" method="post" action="query_code.php"> <td> <table width="78%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong>Query - Contractor History or Job Date</strong></td> </tr> <tr> <td width="118"> </td> <td width="3">:</td> <td width="248"><input name="qry_contractor" type="text" id="mycontractor"></td> </tr> <tr> <td> </td> <td>:</td> <td><input name="qry_jobdate" type="date" id="myjob_date"></td> </tr> <tr> <td>Search for Job numbers with contact information</td> <td> </td> <td><input type="submit" name="Search" value="Search"></td> </tr> </table> </td> </form> </tr> </table> </body> </head> query_code.php <?php session_start(); ob_start(); $hostname='host'; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="database"; // Database name $tbl_name="table"; // Table name // Connect to server and select databse. mysql_connect("$hostname", "$username", "$password")or die("Couldn't connect to SQL Server on $hostname"); mysql_select_db("$db_name")or die("Couldn't select database on $db_name"); $sql="SELECT Jobs.Job_Num, Contractors.F_Name, Contractors.L_Name, Contractors.HomePhone FROM Contractors INNER JOIN Jobs ON Contractors.Cont_Num = Jobs.Cont_Num ORDER BY Jobs.Job_Num DESC"; $result=mysql_query($sql) or die(mysql_error()); header("Location:results.php"); ob_end_flush(); ?> Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted December 8, 2007 Share Posted December 8, 2007 you might have to change the name of the second script to results.php and somewhere (i am not sure if in the submit button or in the form tag) you insert this html code target="_blank" Quote Link to comment Share on other sites More sharing options...
zimmer Posted December 8, 2007 Author Share Posted December 8, 2007 you might have to change the name of the second script to results.php and somewhere (i am not sure if in the submit button or in the form tag) you insert this html code target="_blank" I tried it where results.php is and nothin. I also tried it in the submit button and nothing...but then again I might have had it in the wrong place. Anyone else have any ideas? Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted December 8, 2007 Share Posted December 8, 2007 well i have never done this before so I just guessed, and sorry, that was my only idea :-\ maybe you can do it with javascript, I am not too sure though.... Quote Link to comment Share on other sites More sharing options...
zimmer Posted December 8, 2007 Author Share Posted December 8, 2007 Why am I getting a "Parse error: parse error, unexpected T_VARIABLE in /home/content/r/e/m/remmiz/html/search.php on line 9"? <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var) //trim whitespace from the stored variable // rows to return $limit=10; <--------------HERE!!!! // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } $hostname='p50mysql67.secureserver.net'; // Host name $username="Annas"; // Mysql username $password="XJRsrt00"; // Mysql password $db_name="Annas"; // Database name $tbl_name="contractors"; // Table name //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("$hostname","$username","$password"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("$db_name") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from contractors where f_name like \"%$trimmed%\" order by 1st_field"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; // google echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["1st_field"]; echo "$count.) $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> <!-- © http://www.designplace.org/ --> </body> </html> Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 8, 2007 Share Posted December 8, 2007 unexpected T_VARIABLE errors are rarely on the line stated. Your error is generated up above that, you are missing a semi-colon. $trimmed = trim($var); //trim whitespace from the stored variable PhREEEk Quote Link to comment Share on other sites More sharing options...
zimmer Posted December 8, 2007 Author Share Posted December 8, 2007 Why can't i exec this query? ??? <?php session_start(); ob_start(); $hostname='host'; // Host name $username="user"; // Mysql username $password="password"; // Mysql password $db_name="database"; // Database name $tbl_name="table"; // Table name // Connect to server and select databse. mysql_connect("$hostname", "$username", "$password")or die("Couldn't connect to SQL Server on $hostname"); mysql_select_db("$db_name")or die("Couldn't select database on $db_name"); $query="SELECT * FROM Contractors"; $result=mysql_query($query) or die(mysql_error()); // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query = " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["1st_field"]; echo "$count.) $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ob_end_flush(); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 First you do this $query="SELECT * FROM Contractors"; then a few lines you do this $query = " limit $s,$limit"; So you are overwriting your query, not adding to it. You are missing the . to add them together. 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.