Jump to content

Best Method


Xtremer360

Recommended Posts

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"); ?>

Link to comment
https://forums.phpfreaks.com/topic/236691-best-method/
Share on other sites

        $outputArray = array();
        while ( $row = mysqli_fetch_array ( $titlesResult, MYSQLI_ASSOC ) )
        {
            $outputArray[] ='<a href="/titlehistory/{$row['shortName']}">{$row['titleName']}</a>';
        }
        echo implode('&nbsp|', $outputArray);

Link to comment
https://forums.phpfreaks.com/topic/236691-best-method/#findComment-1216720
Share on other sites

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>";

Link to comment
https://forums.phpfreaks.com/topic/236691-best-method/#findComment-1216772
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.