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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.