Page 1 of 1

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

Posted: Sat May 30, 2009 9:58 pm
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.

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

Posted: Sat May 30, 2009 10:07 pm
by SidewinderX
Is $yes defined?

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

Posted: Sun May 31, 2009 8:37 am
by JKM
yes. :-p

It's a $_GET[] thingy

Edit: Would it make a difference for the first row anyways?

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

Posted: Sun May 31, 2009 9:23 am
by JKM
For some reason, it worked perfectly when I placed the function beneath the sql-connect.