Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8665863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:35:20+00:00 2026-06-12T17:35:20+00:00

We have a basic PHP script to extract the title and description for each

  • 0

We have a basic PHP script to extract the title and description for each job from a MySQL database as simply display this information. This is what it looks like:

$sql        = "SELECT `title`, `desc` FROM jobs WHERE active = 'y'";
$query      = mysql_query($sql) or die('<em><strong>SQL Error:</strong> ' . mysql_error() . '</em>');
$results    = mysql_fetch_assoc($query);

<?php while($result = mysql_fetch_assoc($query)) {
    echo '<div class="left_content" style="margin-top: 15px;">';
    echo "<h2>{$results['title']}</h2>";
    echo "<p>{$results['desc']}</p>";
    echo '</div>';
} ?>

Now, this only extracts one row from the database, but it should extract two. So, I tried the following to replace the while statement:

<?php foreach($results as $result) {
    echo '<div class="left_content" style="margin-top: 15px;">';
    echo "<h2>{$result['title']}</h2>";
    echo "<p>{$result['desc']}</p>";
    echo '</div>';
} ?>

This statement doesn’t work either. This just displays (weirdly) the first character of each column in the first row in the table.

Does anyone have any idea as to why this isn’t working as it should?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:35:21+00:00Added an answer on June 12, 2026 at 5:35 pm

    Result variable you have used is result not results

    Replace

    $sql        = "SELECT `title`, `desc` FROM jobs WHERE active = 'y'";
    $query      = mysql_query($sql) or die('<em><strong>SQL Error:</strong> ' . mysql_error() . '</em>');
    **$results    = mysql_fetch_assoc($query);** // remove this line
    
    <?php while($result = mysql_fetch_assoc($query)) {
        echo '<div class="left_content" style="margin-top: 15px;">';
        echo "<h2>{$results['title']}</h2>";
        echo "<p>{$results['desc']}</p>";
        echo '</div>';
    } ?>
    

    to

    $sql        = "SELECT `title`, `desc` FROM jobs WHERE active = 'y'";
    $query      = mysql_query($sql) or die('<em><strong>SQL Error:</strong> ' . mysql_error() . '</em>');
    
    
    <?php while($result = mysql_fetch_assoc($query)) {
        echo '<div class="left_content" style="margin-top: 15px;">';
        echo "<h2>{$result['title']}</h2>";
        echo "<p>{$result['desc']}</p>";
        echo '</div>';
    } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have a basic php script which is used to display the price
I have a basic PHP script like this: <?php system(/bin/touch /root/testfile); When I run
I have a basic PHP script. $hike_id = $_REQUEST['hike_id']; $height = $_REQUEST['height']; $width =
I have a PHP script that does basic encryption of a string through the
I have a basic php script that calls system(netstat -l) and the reads what
Starting out with php, I have written a basic authentication script which prints out
I have found this little script in PHP that send a simple request to
At the moment I have a really basic PHP script for randomly drawing quotes
I have a basic PHP script that displays the file contents of a directory.
I have a basic PHP mail() script which e-mails users the details of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.