Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect all and as MYSQL Query
    primarykey
    data
    text
    <p>I've got my query that works well for what I'm trying to do, but I'd like to expand this and grab all other informatino from the stockpicks table. What it does now is match a user search for stock symbol then queries my database to see if theres a match, but doesn't allow for other data from that table to be used. This is what I have prior to changes:</p> <pre><code>$sqlCommand = "(SELECT id, symbol as sym FROM stockpicks WHERE symbol LIKE '%$get_quote%')"; </code></pre> <p>This is what I've been attempting to do and my issue.</p> <pre><code>$sqlCommand = "(SELECT * FROM stockpicks symbol as sym WHERE symbol LIKE '%$get_quote%')"; </code></pre> <p>I'm getting this error:</p> <blockquote> <p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as sym WHERE symbol LIKE '%hig%')' at line 1</p> </blockquote> <p>As I said before I'd like to simply call all the information in case it is needed instead of just calling on the symbol. I don't want to match the other information to the search, but I'd like to be able to use the other data to output in combination with the match. If this doesn't make sense let me know. Thanks for all the helpful information you all provide. Its invaluable. Chris</p> <p>Edit : Table structure is </p> <p>id | Symbol | entry | exit | openclosed | entrydate</p> <p>For better understanding I'll include the entire script. I'm trying to have the variables available if it is an open position.</p> <pre><code>&lt;?php error_reporting(E_ALL ^ E_NOTICE); //this is for debugging, remove if you dont need anymore ini_set("display_errors", 1); //this is for debugging, remove if you dont need anymore $searchoutput = ""; $ticker = "goog"; if (isset($_POST['get_quote'])) { $ticker = $_POST['ticker']; } $open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$ticker&amp;f=sl1d1t1c1ohgv&amp;e=.csv", "r"); $quote = fread($open, 1000); fclose($open); $quote = str_replace("\"", "", $quote); $quote = explode(",", $quote); $quote_0 = ($quote[0]); $quote_1 = ($quote[1]); $quote_2 = ($quote[2]); $quote_3 = ($quote[3]); $quote_4 = ($quote[4]); $quote_5 = ($quote[5]); $quote_6 = ($quote[6]); $quote_7 = ($quote[7]); $quote_8 = ($quote[8]); echo "&lt;div class='symbol'&gt;&lt;div class='quote'&gt;Company: $quote_0&lt;/div&gt;&lt;/div&gt;"; echo "&lt;div class='leftofStocks'&gt;&lt;div class='row'&gt;&lt;div class='quote'&gt;Last trade: $$quote_1&lt;/div&gt;"; echo "&lt;div class='quote'&gt;Date: $quote_2&lt;/div&gt;"; echo "&lt;div class='quote'&gt;Time: $quote_3&lt;/div&gt;"; echo "&lt;div class='quote'&gt;From Previous: $$quote_4&lt;/div&gt;&lt;/div&gt;"; echo "&lt;div class='row'&gt;&lt;div class='quote'&gt;Open: $$quote_5&lt;/div&gt;"; echo "&lt;div class='quote'&gt;High: $$quote_6&lt;/div&gt;"; echo "&lt;div class='quote'&gt;Low: $$quote_7&lt;/div&gt;"; echo "&lt;div class='quote'&gt;Volume: $quote_8&lt;/div&gt;&lt;/div&gt;"; if (isset($_POST['get_quote']) &amp;&amp; $_POST['get_quote'] != "") { $ticker = $_POST['ticker']; $get_quote = preg_replace('#[^a-z 0-9?!]#i', '', $_POST['ticker']); $sqlCommand = "(SELECT id, symbol as sym FROM stockpicks WHERE symbol LIKE '%$get_quote%')"; $sym = strtoupper($sym); $get_quote = strtoupper($get_quote); include_once("storescripts/connect_to_mysql.php"); $query = mysql_query($sqlCommand) or die(mysql_error()); $count = mysql_num_rows($query); if($count &gt;= 1){ $search_output .= " &lt;div class='rightOfStocks'&gt;&lt;hr /&gt;It Looks like &lt;strong&gt;'$get_quote'&lt;/strong&gt; is one of our stock picks&lt;hr /&gt; &lt;/div&gt;"; while($row = mysql_fetch_array($query)){ $id = $row["id"]; $sym = $row["sym"]; $sym = strtoupper($sym); $search_output .= " &lt;div class='rightOfStocks'&gt;&lt;h3&gt;Our Pick&lt;/h3&gt;$sym&lt;br /&gt; &lt;br /&gt;$$quote_1 &lt;/div&gt;"; } // close while } else { $search_output = " &lt;div class='rightOfStocks'&gt;&lt;hr /&gt;0 results for &lt;strong&gt;$get_quote&lt;/strong&gt; &lt;hr /&gt;&lt;/div&gt;"; } } ?&gt; &lt;div class="form"&gt; &lt;form method="post" action="&lt;?php echo $_SERVER['REQUEST_URI'];?&gt;"&gt; Get Quote: &lt;input type="text" size="10" maxlength="10" name="ticker"/&gt; &lt;input type="submit" value="Get Quote" name="get_quote" /&gt; Enter any valid stock quote (ie. AAPL HOG RIMM):&lt;br&gt;&lt;/form&gt;&lt;/div&gt; &lt;!--left of stock results close--&gt;&lt;/div&gt;&lt;!--left of stock results close--&gt; &lt;?php echo $search_output ;?&gt; &lt;/div&gt; </code></pre>
    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.
 

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