Ameslee Posted December 19, 2006 Share Posted December 19, 2006 ok i am having trouble with the following code[code]<a href="?search=A"><font size="2"><strong>A</strong></font></a><strong><font size="2"> | <a href="?search=B">B</a> | <a href="?search=C">C</a> | <a href="?search=D">D</a> | <a href="?search=E">E</a> | <a href="?search=F">F</a> | <a href="?search=G">G</a> | <a href="?search=H">H</a> | <a href="?search=I">I</a> | <a href="?search=J">J</a> | <a href="?search=K">K</a> | <a href="?search=L">L</a> | <a href="?search=M">M</a> | <a href="?search=N">N</a> | <a href="?search=O">O</a> | <a href="?search=P">P</a> | <a href="?search=Q">Q</a> | <a href="?search=R">R</a> | <a href="?search=S">S</a> | <a href="?search=T">T</a> | <a href="?search=U">U</a> | <a href="?search=V">V</a> | <a href="?search=W">W</a> | <a href="?search=X">X</a> | <a href="?search=Y">Y</a> | <a href="?search=Z">Z</a></font></strong></p> <p align="left"> </p> </div> <?php $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $query = "SELECT * FROM exhibits WHERE exhibit LIKE '".$_GET['search']."%'"; while ($row = mysql_fetch_object($result)) { echo $row->data."<BR />";} ?>[/code]The following error happens - Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/greenac/public_html/search.php on line 216Can someone plz help? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 19, 2006 Share Posted December 19, 2006 your missing a % at the start of your $_GET Quote Link to comment Share on other sites More sharing options...
Ameslee Posted December 19, 2006 Author Share Posted December 19, 2006 ok i have tried putting the % in and it hasnt made any difference.is this right, im new at this$query = "SELECT * FROM exhibits WHERE exhibit LIKE '%".$_GET['search']."%'"; Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 19, 2006 Share Posted December 19, 2006 hold on hold on. are you trying to grab the first letter???try this:[code=php:0]$query = "SELECT * FROM exhibits WHERE LEFT(exhibit, 1)='{$_GET['search']}";[/code]think thats how you use it... Quote Link to comment Share on other sites More sharing options...
Ameslee Posted December 19, 2006 Author Share Posted December 19, 2006 thanks, tried, but still getting this error - Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/greenac/public_html/search.php on line 216 Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 19, 2006 Share Posted December 19, 2006 i'm just looking over your code. you probably took out your username and password for your mysql on purpose. but place localhost in talking marks. "localhost".[code=php:0]$hostname = "localhost";[/code]now what else. AND DUH! lol... sorry... ummm... try this:[code=php:0]$query = mysql_query("SELECT * FROM exhibits WHERE LEFT(exhibit, 1)='{$_GET['search']}");while ($row = mysql_fetch_object($result)) { echo $row->data."<BR />";}[/code] Quote Link to comment Share on other sites More sharing options...
Ameslee Posted December 19, 2006 Author Share Posted December 19, 2006 still the same error. heaps frustrating! Quote Link to comment Share on other sites More sharing options...
corbin Posted December 19, 2006 Share Posted December 19, 2006 $result = mysql_query($query);Should be in there some where.... Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 19, 2006 Share Posted December 19, 2006 ah yeh. i added the mysql_query sept i didnt notice the $result.Ameslee. Notice in your mysql_fetch_object you have $result, change that to $query. good spotting corbin. Quote Link to comment Share on other sites More sharing options...
Ameslee Posted December 19, 2006 Author Share Posted December 19, 2006 added it in, still the same error, here is my code again[code]<a href="?search=A"><font size="2"><strong>A</strong></font></a><strong><font size="2"> | <a href="?search=B">B</a> | <a href="?search=C">C</a> | <a href="?search=D">D</a> | <a href="?search=E">E</a> | <a href="?search=F">F</a> | <a href="?search=G">G</a> | <a href="?search=H">H</a> | <a href="?search=I">I</a> | <a href="?search=J">J</a> | <a href="?search=K">K</a> | <a href="?search=L">L</a> | <a href="?search=M">M</a> | <a href="?search=N">N</a> | <a href="?search=O">O</a> | <a href="?search=P">P</a> | <a href="?search=Q">Q</a> | <a href="?search=R">R</a> | <a href="?search=S">S</a> | <a href="?search=T">T</a> | <a href="?search=U">U</a> | <a href="?search=V">V</a> | <a href="?search=W">W</a> | <a href="?search=X">X</a> | <a href="?search=Y">Y</a> | <a href="?search=Z">Z</a></font></strong></p> <p align="left"> </p> </div> <?php $hostname = "localhost"; $username = greenac_Admin; $password = greenac; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $query = mysql_query("SELECT * FROM exhibits WHERE LEFT(exhibit, 1)='{$_GET['search']}"); while ($row = mysql_fetch_object($query)) { echo $row->data."<BR />"; } ?>[/code] Quote Link to comment Share on other sites More sharing options...
Ameslee Posted December 19, 2006 Author Share Posted December 19, 2006 have changed the code again, this time a different error, plz help[code]<a href="?search=A"><font size="2"><strong>A</strong></font></a><strong><font size="2"> | <a href="?search=B">B</a> | <a href="?search=C">C</a> | <a href="?search=D">D</a> | <a href="?search=E">E</a> | <a href="?search=F">F</a> | <a href="?search=G">G</a> | <a href="?search=H">H</a> | <a href="?search=I">I</a> | <a href="?search=J">J</a> | <a href="?search=K">K</a> | <a href="?search=L">L</a> | <a href="?search=M">M</a> | <a href="?search=N">N</a> | <a href="?search=O">O</a> | <a href="?search=P">P</a> | <a href="?search=Q">Q</a> | <a href="?search=R">R</a> | <a href="?search=S">S</a> | <a href="?search=T">T</a> | <a href="?search=U">U</a> | <a href="?search=V">V</a> | <a href="?search=W">W</a> | <a href="?search=X">X</a> | <a href="?search=Y">Y</a> | <a href="?search=Z">Z</a></font></strong></p> <p align="left"> </p> </div> <?php $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $query = mysql_query("SELECT * FROM exhibits WHERE LEFT(exhibit, 1)='{$_GET['search']}") or die(mysql_error()); while ($row = mysql_fetch_object($query)) { echo $row->data."<BR />"; } ?>[/code] Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 19, 2006 Share Posted December 19, 2006 please post the new error then. :) Quote Link to comment Share on other sites More sharing options...
Ferenc Posted December 19, 2006 Share Posted December 19, 2006 fill in your db info correctly and this will work[code]<?phpfor ($i = 'A'; $i != 'AA'; $i++){ echo "<a href = \"?search=$i\"> $i </a>";}if(isset($_GET['search']) && $_GET['search'] != ''){ // connect to db $db = mysql_connect('localhost', 'user', 'pass') or die(mysql_error()); $dbi = mysql_select_db('db_name', $db) or die(mysql_error()); $search = $_GET['search']; $sql = mysql_query("SELECT * FROM table_name WHERE table_row LIKE '$search"."%'") or die(mysql_error()); while ($row = mysql_fetch_array($sql)){ // display results echo "<br />" .$row['row to display']. "<br />"; }}?>[/code] Quote Link to comment Share on other sites More sharing options...
Ameslee Posted December 19, 2006 Author Share Posted December 19, 2006 the new error - 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 ''' at line 1im just going to try what Ferenc has posted Quote Link to comment Share on other sites More sharing options...
trq Posted December 19, 2006 Share Posted December 19, 2006 You ought really be using range() to create the listing aswell, so this...[code=php:0]for ($i = 'A'; $i != 'AA'; $i++){[/code]becomes...[code=php:0]foreach (range('A','Z') as $i) {[/code] Quote Link to comment Share on other sites More sharing options...
Ameslee Posted December 19, 2006 Author Share Posted December 19, 2006 ok thats all sorted now, something else, how do i make the results links, so they can be clicked on and then the user is taken to another page with more info? Quote Link to comment Share on other sites More sharing options...
Ferenc Posted December 19, 2006 Share Posted December 19, 2006 I always forget about range() Quote Link to comment Share on other sites More sharing options...
Ferenc Posted December 19, 2006 Share Posted December 19, 2006 add the link in the while loop Quote Link to comment Share on other sites More sharing options...
trq Posted December 19, 2006 Share Posted December 19, 2006 Honestly, a big part of learning to program is learning to think. How do [b]you[/b] think you would make them into links? Quote Link to comment Share on other sites More sharing options...
Ameslee Posted December 19, 2006 Author Share Posted December 19, 2006 ok, but how do i make what displays a link Quote Link to comment Share on other sites More sharing options...
trq Posted December 19, 2006 Share Posted December 19, 2006 You really ought learn [url=http://www.w3schools.com/html/html_links.asp]html[/url] before php considering that is what your trying to get php to output. Quote Link to comment Share on other sites More sharing options...
Ferenc Posted December 19, 2006 Share Posted December 19, 2006 do you understand how the code I posted displays what you want? Quote Link to comment Share on other sites More sharing options...
Ameslee Posted December 19, 2006 Author Share Posted December 19, 2006 yes i understand the code and yes i know how to display links using html, but what i dont understand is how it makes the record a link Quote Link to comment Share on other sites More sharing options...
Ferenc Posted December 19, 2006 Share Posted December 19, 2006 [code]echo "<br />" .$row['row to display']. "<br />";[/code]displays the record...ad the link there[code]echo "<br /><a href=\"where ever you want to go.page\">" .$row['row to display']. "</a><br />";[/code] Quote Link to comment Share on other sites More sharing options...
Ferenc Posted December 19, 2006 Share Posted December 19, 2006 $row contains all the data for each result so it should be easy to display what you need dynamicly 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.