Ameslee Posted February 19, 2007 Share Posted February 19, 2007 <?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 news"; $mysql_result=mysql_query($query,$conn); $nothingInDatabase= true; $i=1; echo("<table width=100%>"); while(($row = mysql_fetch_array($mysql_result)) && ($i<=2)){ if ($nothingInDatabase) $nothingInDatabase = false; $row[1] = wordwrap($row[1], 80, '<br />', true); if (strlen($row[1]) > 100) { $row[1] = substr($row[1],0,100); $row[1] .= "<a href=\"news.php\"> More</a>"; } echo "<tr>"; echo "<td>$row[1]</td></tr>"; echo "<hr>"; $i++; } if ($nothingInDatabase == true) { echo "<tr><td>Please check back later for entries</td></tr>"; } ?> Ok i have two problems - there isnt any space between the records, and i have 2 records displaying and once the more link is pressed, both of the records are displayed on the page in full, where i wont one displayed at a time. hope this makes sense. Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/ Share on other sites More sharing options...
Ameslee Posted February 20, 2007 Author Share Posted February 20, 2007 can anyone help here? Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-189079 Share on other sites More sharing options...
btherl Posted February 20, 2007 Share Posted February 20, 2007 I don't understand what you are asking. Can you explain it in different words, or give an example? Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-189221 Share on other sites More sharing options...
Ameslee Posted February 20, 2007 Author Share Posted February 20, 2007 ok sure, at the moment i have to records showing, which is a paragraph of text. Only a certain amount is showed on the first page and once you click on the more link i was hoping for it to only display the rest of the content for that particualr record, but at the moment it is displaying both records when the more link is clicked. Second problem is the spacing between records, i have a <hr> but it seems to be displaying in the wrong spot - above the records instead of in between. Hope i have explained myself better. thanks Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-189229 Share on other sites More sharing options...
tom100 Posted February 20, 2007 Share Posted February 20, 2007 Your <hr> problem is that it's inside of a table. It needs to be after a </table> tag or inside of one of your <td>'s. For the other problem, I don't know the content of news.php so its hard to say. Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-189231 Share on other sites More sharing options...
Ameslee Posted February 20, 2007 Author Share Posted February 20, 2007 news.php <?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 news"; $mysql_result=mysql_query($query,$conn); $nothingInDatabase= true; echo("<table width=100%>"); while ($row = mysql_fetch_array($mysql_result)) { if ($nothingInDatabase) $nothingInDatabase = false; $row[1] = wordwrap($row[1], 80, '<br />', true); echo "<tr>"; echo "<td>$row[1]</td></tr>"; } if ($nothingInDatabase == true) { echo "<tr><td>Please check back later for entries</td></tr>"; } ?> Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-189242 Share on other sites More sharing options...
Ameslee Posted February 21, 2007 Author Share Posted February 21, 2007 any ideas? Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-190062 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 It sounds like what your saying is: if the full string is: "this is some random string" and the first page shows: "this is some..." if the user clicks More, you want it to only show "random string" instead of "this is some random string" If this is the case, you will need to remove the first part of that string based on the other page. So if you do substr($content, 100); you will only get the remaining text. Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-190069 Share on other sites More sharing options...
Ameslee Posted February 21, 2007 Author Share Posted February 21, 2007 ok thanks i have that: here is the code now: <?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 news"; $mysql_result=mysql_query($query,$conn); $nothingInDatabase= true; $i=1; echo("<table width=100%>"); while(($row = mysql_fetch_array($mysql_result)) && ($i<=2)){ if ($nothingInDatabase) $nothingInDatabase = false; $row[1] = wordwrap($row[1], 80, '<br />', true); if (strlen($row[1]) > 100) { $row[1] = substr($row[1],0,100); $row[1] .= "<a href=\"news.php\"> More</a>"; } echo "<tr>"; echo "<td>$row[1]<hr></td></tr>"; $i++; } if ($nothingInDatabase == true) { echo "<tr><td>Please check back later for entries</td></tr>"; } ?> and the code for news.php <?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 news"; $mysql_result=mysql_query($query,$conn); $nothingInDatabase= true; echo("<table width=100%>"); while ($row = mysql_fetch_array($mysql_result)) { if ($nothingInDatabase) $nothingInDatabase = false; $row[1] = wordwrap($row[1], 80, '<br />', true); echo "<tr>"; echo "<td>$row[1]</td></tr>"; } if ($nothingInDatabase == true) { echo "<tr><td>Please check back later for entries</td></tr>"; } ?> How do i display only one record at a time on the news.php page after clicking on the more link on the event.php. hope u can understand this? Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-190080 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 Hmm... I understand now. You need to be linking with an ID. Your news.php link should instead link like this: <a href="link.php?id=<?=$row['Id'];?>>Read More</a> -Or use whatever column name your using as the Primary Key. Then on the next page, do something similar to this: $id=$_GET['id']; $sql="SELECT * FROM news WHERE `Id` = '{$id}'"; Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-190085 Share on other sites More sharing options...
Ameslee Posted February 21, 2007 Author Share Posted February 21, 2007 i keep getting this error now: Parse error: syntax error, unexpected '<' in /home/greenac/public_html/events.php on line 260 line 260 is the last line so its probably this line that was just put in: $row[1] .= <a href="news.php?id=<?=$row[1];?>>Read More[/url] Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-190096 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 That's because your echoing it. Replace the <?=$row[1];?> with {$row[1]} Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-190105 Share on other sites More sharing options...
Ameslee Posted February 21, 2007 Author Share Posted February 21, 2007 ok still the same error is this right: $row[1] .= <a href="news.php?id={$row[1]}>Read More[/url] Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-190110 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 Ok, the [/url] thing is apparently the result of this forum replacing my end a href tag. Your string should be: $row[1] .= "<a href=\"news.php?id={$row[1]}\">Read More</a>"; In order to end this thread; if you still can't get it working, pm me and I will talk to you on instant messenger. Link to comment https://forums.phpfreaks.com/topic/39106-problem-with-code-strlen-then-a-link/#findComment-190118 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.