Jump to content

simple search question from query.


jbrill

Recommended Posts

I am trying to use a form to call another page (search.php) where search.php finds the text enter in the text field from the database and displays it.

The problem im having is that I cannot seem to get it working... could some one please look at  my code and tell me if it is ok, and if it isn't, help me make it work.

 

My error Im getting is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/morow/public_html/admin/search.php on line 68

 

but i think it has to do with the way i query the database....im new to php...

 

Help is much appreciated, this forum is awesome!

 

 

\\assuming I have already connected tot he database

<?
echo"<table border=\"0\" width=\"80%\" bgcolor=\"#ffffff\" class=\"MainBody1\" cellpaddin=\"0\" cellspacing=\"0\">";
echo"<tr>";
echo"<td class=\"underline\">Quote Number</td><td class=\"underline\">Job Number</td><td class=\"underline\">PO Number</td><td class=\"underline\">Customer</td><td class=\"underline\">Status</td><td class=\"underline\">Action</td>";
echo"<tr>";


$result = mysql_query("SELECT * FROM jobs WHERE prod_number='".$_GET['prod_number']."'");

while($row = mysql_fetch_array($result))
{

	 echo "<tr><td>" . $row['id'] .  "</td><td>"  . $row['job_number'] ."</td><td>" . $row['po_number'] . "</td><td>" . $row['customer'] . "</td><td>" . $row['status'] . "</td><td> 
  
  
  <a class=\"link\" href=\"admin_modnews.php?idr=".$row['id']."&table=jobs\"><img src=\"images/actionEdit.gif\" border=\"0\"></a> <a class=\"link\" href=\"admin_delete.php?idr=".$row['id']."&table=jobs\"><img src=\"images/actionDelete.gif\" border=\"0\"></a>
  
  
  </td></tr>";

}
echo"</table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/58441-simple-search-question-from-query/
Share on other sites

try this please.

 

<?php
echo"<table border=\"0\" width=\"80%\" bgcolor=\"#ffffff\" class=\"MainBody1\" cellpaddin=\"0\" cellspacing=\"0\">";
echo"<tr>";
echo"<td class=\"underline\">Quote Number</td><td class=\"underline\">Job Number</td><td class=\"underline\">PO Number</td><td class=\"underline\">Customer</td><td class=\"underline\">Status</td><td class=\"underline\">Action</td>";
echo"<tr>";


$result = mysql_query("SELECT * FROM jobs WHERE  like prod_number='%".$_GET['prod_number']."%' ");

while($row = mysql_fetch_array($result))
{

	echo "<tr><td>" . $row['id'] .  "</td><td>"  . $row['job_number'] ."</td><td>" . $row['po_number'] . "</td><td>" . $row['customer'] . "</td><td>" . $row['status'] . "</td><td> 
  
  
  <a class=\"link\" href=\"admin_modnews.php?idr=".$row['id']."&table=jobs\"><img src=\"images/actionEdit.gif\" border=\"0\"></a> <a class=\"link\" href=\"admin_delete.php?idr=".$row['id']."&table=jobs\"><img src=\"images/actionDelete.gif\" border=\"0\"></a>
  
  
  </td></tr>";

}
echo"</table>";
?>

<?php
echo"<table border=\"0\" width=\"80%\" bgcolor=\"#ffffff\" class=\"MainBody1\" cellpaddin=\"0\" cellspacing=\"0\">";
echo"<tr>";
echo"<td class=\"underline\">Quote Number</td><td class=\"underline\">Job Number</td><td class=\"underline\">PO Number</td><td class=\"underline\">Customer</td><td class=\"underline\">Status</td><td class=\"underline\">Action</td>";
echo"<tr>";


$result = mysql_query("SELECT * FROM jobs WHERE  prod_number like ='%".$_GET['prod_number']."%' ");

while($row = mysql_fetch_array($result))
{

	echo "<tr><td>" . $row['id'] .  "</td><td>"  . $row['job_number'] ."</td><td>" . $row['po_number'] . "</td><td>" . $row['customer'] . "</td><td>" . $row['status'] . "</td><td> 
  
  
  <a class=\"link\" href=\"admin_modnews.php?idr=".$row['id']."&table=jobs\"><img src=\"images/actionEdit.gif\" border=\"0\"></a> <a class=\"link\" href=\"admin_delete.php?idr=".$row['id']."&table=jobs\"><img src=\"images/actionDelete.gif\" border=\"0\"></a>
  
  
  </td></tr>";

}
echo"</table>";
?>

post the select statement when tried this ok.

 

<?php
echo"<table border=\"0\" width=\"80%\" bgcolor=\"#ffffff\" class=\"MainBody1\" cellpaddin=\"0\" cellspacing=\"0\">";
echo"<tr>";
echo"<td class=\"underline\">Quote Number</td><td class=\"underline\">Job Number</td><td class=\"underline\">PO Number</td><td class=\"underline\">Customer</td><td class=\"underline\">Status</td><td class=\"underline\">Action</td>";
echo"<tr>";

$x=$_GET['prod_number'];
$result = " SELECT * FROM `jobs` WHERE `prod_number` like ='%$x%' ";
$result=mysql_query($result)or die("mysql_error");


echo $result;

while($row = mysql_fetch_array($result))
{

	echo "<tr><td>" . $row['id'] .  "</td><td>"  . $row['job_number'] ."</td><td>" . $row['po_number'] . "</td><td>" . $row['customer'] . "</td><td>" . $row['status'] . "</td><td> 
  
  
  <a class=\"link\" href=\"admin_modnews.php?idr=".$row['id']."&table=jobs\"><img src=\"images/actionEdit.gif\" border=\"0\"></a> <a class=\"link\" href=\"admin_delete.php?idr=".$row['id']."&table=jobs\"><img src=\"images/actionDelete.gif\" border=\"0\"></a>
  
  
  </td></tr>";

}
echo"</table>";
?>

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.