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 968593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:30:29+00:00 2026-05-16T02:30:29+00:00

I have a little problem that I don’t understand. I have a db that

  • 0

I have a little problem that I don’t understand. I have a db that has an owner and type (and more off course). I want to get a list of all the type values that has owner equal to the current user, but I get only two result

$sql = "SELECT type FROM cars WHERE owner='".mysql_real_escape_string($_SESSION['username'])."' AND selling='0' ORDER BY id DESC "; 

 $result = mysql_query($sql,$con); 

 print_r(mysql_fetch_array($result));

prints out:

Array ( [0] => 18 [type] => 18 )

and

$sql = "SELECT type FROM cars WHERE owner='".mysql_real_escape_string($_SESSION['username'])."' AND selling='0' "; 

prints out:

Array ( [0] => 16 [type] => 16 ) 

And the result should be something like 19, 19, 18, 17, 16 in an array. Thats all the types that has me as set as owner.

I have got this working now:

for ($x = 0; $x < mysql_num_rows($result); $x++){
 $row = mysql_fetch_assoc($result);  
 echo $row['type']; 
}

Here I print out all the values correctly, but I need to create an array with all the values. I though I could use array_push, but there most be a better way of doing it. I thought I would get all the type values with a simple mysql query.

  • 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-05-16T02:30:29+00:00Added an answer on May 16, 2026 at 2:30 am

    Very often this is done in a while loop:

    $types = array();
    
    while(($row =  mysql_fetch_assoc($result))) {
        $types[] = $row['type'];
    }
    

    Have a look at the examples in the documentation.

    The mysql_fetch_* methods will always get the next element of the result set:

    Returns an array of strings that corresponds to the fetched row, or FALSE if there are no more rows.

    That is why the while loops works. If there aren’t any rows anymore $row will be false and the while loop exists.

    It only seems that mysql_fetch_array gets more than one row, because by default it gets the result as normal and as associative value:

    By using MYSQL_BOTH (default), you’ll get an array with both associative and number indices.

    Your example shows it best, you get the same value 18 and you can access it via $v[0] or $v['type'].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little Java problem I want to translate to Python. Therefor I
i have little problem with boost::asio library. My app receive and process data asynchronously,
I have a little problem with a Listview. I can load it with listview
I've run on a little problem today: I have a JS drop down menu
I have a little demonstration below of a peculiar problem. using System; using System.Windows.Forms;
I’m having a little Architecture problem. In my project I have a Business Logic
I have a problem with a little .Net web application which uses the Amazon
I have little knowledge of Flash but for a little Flash game I have
I've been using python for years, but I have little experience with python web
I need MatLab for 2D and 3D modeling. I have little experience in MatLab.

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.