Xtremer360 Posted May 17, 2011 Share Posted May 17, 2011 I know I'm posting this inside the PHP coding board but I'm curious on how most handle this situation. I have a page that uses php to retrieve data from my database and I want to have it place a | in between each of the returned data which it does but it still places one after the last returned row. I'm wondering if I should do this with jquery load and then have it place that character in between each of the data or if there's a way to do it with php or what? Any ideas? <?php require ("../header.php"); ?> <div id="titlehistory" class="content"> <h1 class="pageheading">Title History</h1> <?php $titlesQuery =" SELECT titles.titleName, titles.shortName FROM titles WHERE titles.statusID = 1 ORDER BY titles.ID"; $titlesResult = mysqli_query($dbc,$titlesQuery); ?> <p><span class="minilinks"> <?php while ( $row = mysqli_fetch_array ( $titlesResult, MYSQLI_ASSOC ) ) { $fieldarray=array('titleName','shortName'); foreach ($fieldarray as $fieldlabel) { ${$fieldlabel} = $row[$fieldlabel]; } echo '<a href="/titlehistory/'.$shortName.'">'.$titleName.'</a> |'; } ?> </span></p> <p class="nohistory">Please select a title to view.</p> </div> <?php require ("../footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/236691-best-method/ Share on other sites More sharing options...
Psycho Posted May 17, 2011 Share Posted May 17, 2011 $outputArray = array(); while ( $row = mysqli_fetch_array ( $titlesResult, MYSQLI_ASSOC ) ) { $outputArray[] ='<a href="/titlehistory/{$row['shortName']}">{$row['titleName']}</a>'; } echo implode(' |', $outputArray); Quote Link to comment https://forums.phpfreaks.com/topic/236691-best-method/#findComment-1216720 Share on other sites More sharing options...
QuickOldCar Posted May 17, 2011 Share Posted May 17, 2011 yup, was just gonna say implode() myself Quote Link to comment https://forums.phpfreaks.com/topic/236691-best-method/#findComment-1216721 Share on other sites More sharing options...
Xtremer360 Posted May 17, 2011 Author Share Posted May 17, 2011 There's a t_string error with this line though. $outputArray[] ='<a href="/titlehistory/{$row['shortName']}">{$row['titleName']}</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/236691-best-method/#findComment-1216723 Share on other sites More sharing options...
Psycho Posted May 18, 2011 Share Posted May 18, 2011 There's a t_string error with this line though. $outputArray[] ='<a href="/titlehistory/{$row['shortName']}">{$row['titleName']}</a>'; Sorry, I thought the string was defined with double quotes (so the variales would be interpreted). Try this: $outputArray[] ="<a href='/titlehistory/{$row['shortName']}'>{$row['titleName']}</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/236691-best-method/#findComment-1216772 Share on other sites More sharing options...
Xtremer360 Posted May 18, 2011 Author Share Posted May 18, 2011 Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/236691-best-method/#findComment-1216802 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.