Replace script - drops the first mysql row.. (SOLVED)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Replace script - drops the first mysql row.. (SOLVED)

Post by JKM »

Code: Select all

<table style="width: 100%;">
<?php
require('functions.php');
dbCon();
$query = mysql_query("SELECT * FROM list ORDER by status DESC, criteria_".$yes."_list ASC");
function replaceChar ($source, $replace) {
    $retval = array();
    $source = str_split($source);
    foreach($source as $key => $char) {
        if(isset($replace[$char])) {
            $retval[$key] = $replace[$char];
            continue;
        }            
        $retval[$key] = $char;
    }        
    return implode('', $retval);
}
while($fetch = mysql_fetch_array($query)) {
?><tr>
    <td><?php
        $source = $fetch['criteria_'.$yes.'_list'];
        $replace = array (
            'a' => '<span title="hello">a</span>',
            'b' => '<span title="good bye">b</span>',
            'c' => '<span title="hey">c</span>',
        );
        echo replaceChar($source, $replace);
    ?></td>
    </tr>
<?php } ?>
</table>
The problem is that the first mysql row isn't echoed. When removing the php code inside the <td></td>, the first row is also echoed. Also, when doing the query in a mysql query browser, the first row is listed.
Last edited by JKM on Sun May 31, 2009 9:23 am, edited 1 time in total.
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Re: Replace script - drops the first mysql row..

Post by SidewinderX »

Is $yes defined?
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: Replace script - drops the first mysql row..

Post by JKM »

yes. :-p

It's a $_GET[] thingy

Edit: Would it make a difference for the first row anyways?
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: Replace script - drops the first mysql row.. (SOLVED)

Post by JKM »

For some reason, it worked perfectly when I placed the function beneath the sql-connect.
Post Reply