Jump to content

Recommended Posts

Good morning everyone! - in the same time zone :) Lately I've been processing my dreams through php code, it's so weird.

 

Anyways, I used to connect with the original MYSQL extension and then I read that the object-oriented method is better. I used that but I'm not getting the same results. For example I have a categories table and a topics table. I'm using while loops to display all categories and each topic that belongs to each one.

 

The object-oriented code I'm using is..

 

 

require_once("/functions/db_fns.php");

$connection = dbConnect(); //db connection function

//prepare Categories query

$sql = "SELECT * FROM categories";

$result = $connection->query($sql) or die(mysqli_error($connection));

while ($row = $result->fetch_assoc()) {	
echo strtoupper("<li>{$row["cat_name"]}</li>");

//prepare Topics query

$sql = "SELECT * FROM topics WHERE cat_id = {$row["cat_id"]}";

$result = $connection->query($sql) or die(mysqli_error($connection));

while ($row = $result->fetch_assoc()) {	

//find out how many records were retrieved
$numRows = $result->num_rows;

$topic_id=$row['topic_id'];
$topic_name=$row['topic_name'];
$topic_date=$row['topic_date'];
$numRows = $result->num_rows;

echo "<a href=\"single_topic.php?topic=" . urlencode($topic_id) . "\">
$topic_name</a> ";	
echo $numRows;

}//end topic while

}//end category while

 

 

With the original MYSQL extension I used to get all the categories and related topics. But now I get just 1 catgeory and 1 topic. I'm trying to figure out why they're not all displaying.. :confused:

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.