Note that there are some explanatory texts on larger screens.

plurals
  1. POSearch Function results within table
    primarykey
    data
    text
    <p>I am trying to get the results of my search page to be within a <code>&lt;table&gt;</code>. This code does return the data I need, I just don't know how to structure it to output it the way I want.</p> <pre><code>&lt;?php include('connection.php'); $error = array(); $results = array(); if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); if (strlen($searchTerms) &lt; 3) { $error[] = "Search terms must be 3 or more characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); } if (count($error) &lt; 1) { $searchSQL = " SELECT ITEM_NUMBER, ITEM_NAME, VENDOR, CONCAT('$', FORMAT(WHOLESALE_PRICE, 2)) AS WHOLESALE_PRICE, CONCAT('$', FORMAT(RETAIL_PRICE, 2)) AS RETAIL_PRICE, CONCAT('$', FORMAT(RETAIL_PRICE - WHOLESALE_PRICE, 2)) AS PROFIT, DESCRIPTION FROM PRODUCTS WHERE "; $types = array(); if (count($types) &lt; 1) $types[] = "`ITEM_NUMBER` LIKE '%{$searchTermDB}%' OR `ITEM_NAME` LIKE '% {$searchTermDB}%' OR `VENDOR` LIKE '%{$searchTermDB}%'"; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `ITEM_NUMBER`"; $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.&lt;br/&gt;" . mysql_error() . "&lt;br /&gt;SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) &lt; 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = " {$i})&lt;br /&gt; Item Number : {$row['ITEM_NUMBER']}&lt;br /&gt; Item Name : {$row['ITEM_NAME']}&lt;br /&gt; Vendor : {$row['VENDOR']}&lt;br /&gt; Wholesale Price : {$row['WHOLESALE_PRICE']}&lt;br /&gt; Retail Price : {$row['RETAIL_PRICE']}&lt;br /&gt; Profit : {$row['PROFIT']}&lt;br /&gt; Description : {$row['DESCRIPTION']}&lt;br /&gt;&lt;br /&gt;"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?&gt; &lt;html&gt; &lt;title&gt;Search Products&lt;/title&gt; &lt;style type="text/css"&gt; #error { color: red; } &lt;/style&gt; &lt;body&gt; &lt;?php echo (count($error) &gt; 0)?"The following had errors:&lt;br /&gt;&lt;span id=\"error\"&gt;" . implode("&lt;br /&gt;", $error) . "&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;":""; ?&gt; &lt;form method="GET" action="&lt;?php echo $_SERVER['PHP_SELF'];?&gt;" name="searchForm"&gt; Search For (Item Number, Name or Vendor) : &lt;input type="text" name="search" value="&lt;?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?&gt;" /&gt;&lt;br /&gt; &lt;input type="submit" name="submit" value="Search!" /&gt;&lt;input type="reset" value="Reset" name="Reset" /&gt; &lt;/form&gt; &lt;?php echo (count($results) &gt; 0)?"Your search term: {$searchTerms} &lt;br /&gt; Returned:&lt;br /&gt;&lt;br /&gt;" . implode("", $results):""; ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The desired look is something to the likes of this:</p> <pre><code>--------------------------------- |Item Number : | 0000-0001 | |-------------------------------- |Item Name : | test | |-------------------------------- |Vendor : | me | |-------------------------------- |Wholesale Price : | $10.00 | |-------------------------------- |Retail Price : | $20.00 | |-------------------------------- |Profit : | $10.00 | |-------------------------------- |Description : | Test | |-------------------------------- </code></pre> <p>I have not done PHP in close to 4 or 5 years, I am not even close to what you would call intermediate. I truly don't know where to do so and how in the code. This code is many different snippets I have found and puzzled together to work as it is now. </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