Page 1 of 1

Variable not working under mysqli_num_rows...

Posted: Mon Jul 09, 2007 12:30 am
by wasir
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


The variable $question works good if not used within if statement, but it doesn't show the data when used under if (mysqli_num_rows) statement. 

can any help me with what I am doing wrong here... please...

Code: Select all

$sid = $_GET['sid'];

    if (!$resultdisp = @mysqli_query($link, 'SELECT users.username, users.name, tblquestion.id, tblquestion.question, tblreply.* FROM `users`, `tblquestion`, `tblreply` WHERE users.username = tblreply.username AND tblreply.questid = tblquestion.id AND questid = \'' . $sid . '\'')) {
        echo getHeader();
        echo '<div id=centreall><p>Error: ' . mysqli_error($link) . '.</p></div>';
        echo getFooter();
        mysqli_close($link);
        exit;
    }

    while ($rowquest = mysqli_fetch_assoc($resultdisp)) {
        $question = $rowquest['question'];
    }
    
    $row_cnt = mysqli_num_rows($resultdisp);

    if (!$row_cnt >0) {
    	echo getHeader();
        echo '<div id=logged><p> You are logged in as <em>' . $_SESSION['valid_user'] . '</em> | <a href=logout.php5>logout</a></p></div>';
        echo '<div id=centreall><p>' . $question . '</p></div>';  //<-- THIS ONE NOT SHOWING
        echo '<div id=centreall><p> This question haven\'t received any reply yet.</p></div>';
        echo '<p class=nav><a href=admlist.php5>back</a></p>';
        echo getFooter();
    	exit;
    }    
    
    echo getHeader();
    echo '<div id=logged><p> You are logged in as <em>' . $_SESSION['valid_user'] . '</em> | <a href=logout.php5>logout</a></p></div>';
    echo '<div id=centreall><p>' . $question . '</p></div>';  //<-- THIS ONE SHOWS
?>
        <form>
        <div id="admform">
<?php
    mysqli_data_seek($resultdisp, 0);
    while ($row = mysqli_fetch_assoc($resultdisp)) {
        echo '<fieldset>';
        echo '<legend>' . $row['name'] . '</legend>';
        echo '<p class=repday><i>replied on</i> ' . date('d M Y', strtotime($row['repday'])) . '</p>';
        echo '<p class=rep>' . $row['reply'] . '</p>';
        echo '<p><i>' . $row['comment'] . '</i></p>';
        echo '</fieldset>';
    }
    mysqli_free_result($resultdisp);
    mysqli_close($link);
?>
        </div>
        </form>
<?php
        echo '<p class=nav><a href=admlist.php5>back</a></p>';
        echo getFooter();
        exit;
}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Jul 09, 2007 6:15 am
by volka
if (!$row_cnt >0) {
echo getHeader();
echo '<div id=logged><p> You are logged in as <em>' . $_SESSION['valid_user'] . '</em> | <a href=logout.php5>logout</a></p></div>';
echo '<div id=centreall><p>' . $question . '</p></div>'; <-- THIS ONE NOT SHOWING
echo '<div id=centreall><p> This question haven\'t received any reply yet.</p></div>';
echo '<p class=nav><a href=admlist.php5>back</a></p>';
echo getFooter();
exit;
}
If !$row_cnt >0 is true then $row_cnt is 0 (in this script) and no record has been fetched, i.e. $question = $rowquest['question']; never happend.

Re: Variable not working under mysqli_num_rows...

Posted: Mon Jul 09, 2007 6:16 am
by superdezign
wasir wrote:The variable $question works good if not used within if statement, but it doesn't show the data when used under if (mysqli_num_rows) statement.
Have you tried echoing the result of mysqli_num_rows() to the screen?

Thanks guys...

Posted: Mon Jul 09, 2007 8:56 pm
by wasir
This is my first post ever... still learning.

It's making clear sense now.

Thanks again for yous help. :D