Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL retrieval from database not retrieving multiple rows
    primarykey
    data
    text
    <p>I'm trying to retrieve all data with the <code>LIKE</code> query from the users input and match it to the database, it works but only returns one record but I have many records in the table. </p> <p>It returns the closest record it can find,</p> <p>so say for example I have 2 records who's ItemDesc field contains the characters 'The', when I search for 'The' in my input box and click submit it returns the closest (earliest created) record when it is supposed to return both.</p> <pre><code>&lt;?php $username = "a3355896_guy"; $password = "++++++"; $hostname = "mysql5.000webhost.com"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); mysql_select_db("a3355896_book") or die("Unable to connect to database"); $ItemDesc = $_POST['ItemDesc']; $query = "select * from StockItems where ItemDesc LIKE '%$ItemDesc%'"; $result=mysql_query($query); $num=mysql_num_rows($result); mysql_close(); ?&gt; </code></pre> <p>Sorry was supposed to included the retrieval: </p> <pre><code>&lt;?php if ($num&gt;0) { echo "&lt;center&gt;&lt;table border=1&gt;&lt;tr&gt;&lt;th&gt;Item Code&lt;/th&gt;&lt;th&gt;Item Desc&lt;/th&gt;"; echo "&lt;th&gt;Item Stock Qty&lt;/th&gt;"; echo "&lt;th&gt;Item Unit Price&lt;/th&gt;&lt;th&gt;Item Category&lt;/th&gt;&lt;/tr&gt;"; $ItemCode = mysql_result($result,$i,"ItemCode"); $ItemDesc = mysql_result($result,$i,"ItemDesc"); $ItemStockQty = mysql_result($result,$i,"ItemStockQty"); $ItemUnitPrice = mysql_result($result,$i,"ItemUnitPrice"); $ItemCategory = mysql_result($result,$i,"ItemCategory"); echo "&lt;tr&gt;&lt;td&gt;$ItemCode&lt;/td&gt;&lt;td&gt;$ItemDesc&lt;/td&gt;&lt;td align=right&gt;"; echo "$ItemStockQty&lt;/td&gt;"; echo "&lt;td align=right&gt;$ItemUnitPrice&lt;/td&gt;"; echo "&lt;td&gt;$ItemCategory&lt;/td&gt;&lt;/tr&gt;"; echo "&lt;/table&gt;&lt;/center&gt;"; } else { echo "&lt;form name='DeleteStock2'&gt;"; echo "&lt;p&gt; Sorry, $ItemDesc does not exist!&lt;p&gt;"; echo "&lt;input type='button' value='Leave' onclick='history.go(-1)'&gt;"; } </code></pre> <p>?> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload