yobo Posted March 2, 2007 Share Posted March 2, 2007 here is my page with the letters on and the code is shown <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <a href="searchByList.php?index=#">#</a> <a href="searchByList.php?index=A">A</a> <a href="searchByList.php?index=B">B</a> <a href="searchByList.php?index=C">C</a> <a href="searchByList.php?index=D">D</a> </body> </html> and this is the reciving script <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php include 'db.inc.php'; $colname = "index"; if (isset($_GET['index'])) { $colname = (get_magic_quotes_gpc()) ? $_GET['index'] : addslashes($_GET['index']); } if ($colname == "A"){ $colname = preg_replace("/[^0-9]/", "" , $colname); } $query_rsSearchList = "SELECT * FROM name WHERE name1 LIKE '$colname%' AND id = id ORDER BY name1 ASC "; ?> </body> </html> but for some reasson no data is being outputted back to the broswer it is comming up with a blank page, i know i need an echo statement in there but i don't know where to add it and what variable to add Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/ Share on other sites More sharing options...
Orio Posted March 2, 2007 Share Posted March 2, 2007 For what is this part?? "AND id = id" Also, I don't understand what you are doing with preg_replace(), as far as I can see- it destroys the "A"... Orio. Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198174 Share on other sites More sharing options...
idevlabsdotcom Posted March 2, 2007 Share Posted March 2, 2007 that's because you never execute the query or echo anything. if you're using MySQL for example, you would have to add: $result = mysql_query($query_rsSearchList); then you'd have to output the results: while($row = mysql_fetch_assoc($result)){ echo $row['colname1'] . " " . $row['colname2'] . "" . $row['colname3'] . "<br>"; } and replace the colname stuff with the names of the columns in your table. also you're going to have problems with your SQL most likely. try changing it to: $query_rsSearchList = "SELECT * FROM name WHERE name1 LIKE '$colname%' ORDER BY name1 ASC "; where id=id isn't going to do anything unless you have a column named id, and you have the string "id" in it for some bizarre reason. but even then you would need it to read: where id='id' also I don't get the point of that preg_replace()... Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198177 Share on other sites More sharing options...
yobo Posted March 3, 2007 Author Share Posted March 3, 2007 ok i have got it to display the page and the data the only problem is that when i click on the letter a it pulls all the data from the certain table and not just the names that begin with the letter a here is my updated code <?php include 'db.inc.php'; $colname = "A"; if (isset($_GET['index'])) {$colname = (get_magic_quotes_gpc()) ? $_GET['index'] : addslashes($_GET['index']);} if ($colname == "A") $sql = "SELECT * FROM name WHERE name1 LIKE '$a%' ORDER BY name1 ASC "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo $row['name1'] . " " . $row['age'] . "<br>"; } mysql_free_result($result); ?> Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198474 Share on other sites More sharing options...
JasonLewis Posted March 3, 2007 Share Posted March 3, 2007 use the LEFT function in mysql. <?php include 'db.inc.php'; $colname = "A"; if (isset($_GET['index'])) {$colname = (get_magic_quotes_gpc()) ? $_GET['index'] : addslashes($_GET['index']);} $sql = "SELECT * FROM name WHERE LEFT(`name1`,1)='{$colname}' ORDER BY name1 ASC "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo $row['name1'] . " " . $row['age'] . " "; } mysql_free_result($result); ?> Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198476 Share on other sites More sharing options...
yobo Posted March 3, 2007 Author Share Posted March 3, 2007 thanks Project fear for helping me but i have another problem for some reasson the results appear all on one line how do i get it so that the appear below each other in a list while($row = mysql_fetch_assoc($result)){ echo $row['name1'] . " " . $row['age'] . "; } but the results don't go onto a new line Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198495 Share on other sites More sharing options...
chronister Posted March 3, 2007 Share Posted March 3, 2007 <?php while($row = mysql_fetch_assoc($result)){ echo $row['name1'] . " " . $row['age'] ."<br>"; } ?> The <br> tag is needed to insert a line break Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198585 Share on other sites More sharing options...
yobo Posted March 3, 2007 Author Share Posted March 3, 2007 <?php while($row = mysql_fetch_assoc($result)){ echo $row['name1'] . " " . $row['age'] ."<br>"; } ?> The <br> tag is needed to insert a line break i have done what you said above and it is still displaying on one line i have been working to try and get it on seperate lines for over 4+ hours and still can't get it to work Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198592 Share on other sites More sharing options...
chronister Posted March 3, 2007 Share Posted March 3, 2007 hmmmmmmmmmmmmmmmmm... that br tag should have forced a new line. just for fun, add about 2 or 3 more br tags and see if that does anything <?php while($row = mysql_fetch_assoc($result)){ echo $row['name1'] . " " . $row['age'] ."<br><br><br>"; } ?> This SHOULD put 2 blank line between each row of data. Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198626 Share on other sites More sharing options...
yobo Posted March 3, 2007 Author Share Posted March 3, 2007 still dose not seem to want to work here is all my code for your to see my db.inc.php code: PHP Code: <?php //database connection settings $dbcon = @mysql_connect('localhost', 'root', 'root'); if (!$dbcon) { exit('Error Connecting To The Site Database.'); } if (!@mysql_select_db('letters', $dbcon)) { exit('Error opening the site database.'); } ?> my indiex.php code: PHP Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <a href="searchByList.php?index=#">#</a> <a href="searchByList.php?index=A">A</a> <a href="searchByList.php?index=B">B</a> <a href="searchByList.php?index=C">C</a> <a href="searchByList.php?index=D">D</a> </body> </html> my searchByList.php code: PHP Code: <?php include 'db.inc.php'; $colname = "A"; if (isset($_GET['index'])) {$colname = (get_magic_quotes_gpc()) ? $_GET['index'] : addslashes($_GET['index']);} $sql = "SELECT * FROM name WHERE LEFT(`name1`,1)='{$colname}' ORDER BY name1 ASC "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo $row['name1'] . " " . $row['age'] . " "; } mysql_free_result($result); ?> <?php $colname = "B"; if (isset($_GET['index'])) {$colname = (get_magic_quotes_gpc()) ? $_GET['index'] : addslashes($_GET['index']);} $sql = "SELECT * FROM name WHERE LEFT(`name1`,0)='{$colname}' ORDER BY name1 ASC "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo $row['name1'] . " " . $row['age'] . '<br />'; } mysql_free_result($result); ?> and my table structure in my database is this +-------+-----+----+ | name1 | age | id | +-------+-----+----+ | joe | 19 | 1 | | abc | 34 | 2 | | max | 89 | 3 | | bcd | 45 | 4 | | ben | 35 | 5 | +-------+-----+----+ Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198654 Share on other sites More sharing options...
yobo Posted March 3, 2007 Author Share Posted March 3, 2007 anyone ??? Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198687 Share on other sites More sharing options...
chronister Posted March 3, 2007 Share Posted March 3, 2007 <?php //database connection settings $dbcon = @mysql_connect('localhost', 'root', 'root'); if (!$dbcon) { exit('Error Connecting To The Site Database.'); } if (!@mysql_select_db('letters', $dbcon)) { exit('Error opening the site database.'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <a href="searchByList.php?index=#">#[/url] <a href="searchByList.php?index=A">A[/url] <a href="searchByList.php?index=B">B[/url] <a href="searchByList.php?index=C">C[/url] <a href="searchByList.php?index=D">D[/url] </body> </html> <?php include 'db.inc.php'; $colname = "A"; if (isset($_GET['index'])) {$colname = (get_magic_quotes_gpc()) ? $_GET['index'] : addslashes($_GET['index']);} $sql = "SELECT * FROM name WHERE LEFT(`name1`,1)='{$colname}' ORDER BY name1 ASC "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo $row['name1'] . " " . $row['age'] ."<br>"; // added a br tag here } mysql_free_result($result); ?> <?php $colname = "B"; if (isset($_GET['index'])) {$colname = (get_magic_quotes_gpc()) ? $_GET['index'] : addslashes($_GET['index']);} $sql = "SELECT * FROM name WHERE LEFT(`name1`,0)='{$colname}' ORDER BY name1 ASC "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo $row['name1'] . " " . $row['age'] . '<br>';// added a br tag here } mysql_free_result($result); ?> I added the br tags into the code above. Try that and post back Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198713 Share on other sites More sharing options...
yobo Posted March 3, 2007 Author Share Posted March 3, 2007 thanks man it works, what was the problem by the way? kinda strange that you have to add the br tag twice one for the A section and one for the B section Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198742 Share on other sites More sharing options...
chronister Posted March 3, 2007 Share Posted March 3, 2007 No, this is exactly what its supposed to do. When you are doing a loop and you want each item to be on a separate line you have to add the br tag where you want the new line to be. If you have multiple loops as you do, then a br tag has to be added to each one because adding it to one part will not transfer it to another place in the script. Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198757 Share on other sites More sharing options...
yobo Posted March 3, 2007 Author Share Posted March 3, 2007 fair enought, once again man and thanks phpfreaks rockz!! Link to comment https://forums.phpfreaks.com/topic/40924-solved-my-a-z-links-are-not-showing/#findComment-198760 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.