Jump to content

rayv

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rayv's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you Guys, I already figure it out. Since the connection to the database was outside of the function, it was throwing an error. I managed to put it inside the function and it worked.
  2. original post shows: "while($row = mysql_fetch_array($result, MYSQLI_ASSOC))" which does not work. The one that works is: "while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))" I forgot to correct the code to use mysqli_fetch instead i left it as mysql_fetch This code works outside of the function: $q = "SELECT * FROM posts p, threads t, users u where t.thread_id = p.thread_id and u.user_id = t.user_id ORDER BY p.posted_on DESC LIMIT 0, 5"; $result = mysqli_query($dbc, $q); while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { extract($row); echo "<li><a target='_blank' href='http://www.i-tech-system.com/forum/viewtopic.php?f=".$p.post_id."&t=".$t.thread_id."'> <strong>".$subject."</strong></a><br /><small>Member since ".$p.posted_on."</small></li>"; }
  3. outside of the function, YES. If I remove: latestpost() { } it works fine. Note, I am calling the function from another file.
  4. When I run my code outside of a function it works but when i put it on this function I get these three errors: 1. mysql_fetch_array() expects parameter 1 to be resource, null given on line 20 which is: "while($row = mysql_fetch_array($result, MYSQLI_ASSOC))" 2. on line 19: mysqli_query() expects parameter 1 to be mysqli, null given which is: "$result = mysqli_query($dbc, $q);" 3. on line 19: Undefined variable: dbc Here is the function call: <h5>Latest Posts</h5> <div class="box"> <div class="content"> <ul> <?php latestpost(); ?> </ul> </div> </div> Here is the function: require_once ('mysqli_connect.php'); function latestpost() { $q = "SELECT * FROM posts p, threads t, users u where t.thread_id = p.thread_id and u.user_id = t.user_id ORDER BY p.posted_on DESC LIMIT 0, 5"; $result = mysqli_query($dbc, $q); while($row = mysql_fetch_array($result, MYSQLI_ASSOC)) { extract($row); echo "<li><a target='_blank' href='http://localhost/sample/forum/viewtopic.php?f=". $p.post_id."&t=".$t.thread_id."'> <strong>".$subject."</strong></a><br /><small>Member since ". $p.posted_on."</small></li>"; } } Here is the connection: <?php mysqli_connect.php is: DEFINE ('DB_USER', 'username'); DEFINE ('DB_PASSWORD', 'password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'database'); // Make the connection: $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); // Set the encoding... mysqli_set_charset($dbc, 'utf8'); // end
×
×
  • 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.