Jump to content

Simple echo of data from DB. Help.


kleptik

Recommended Posts

I have one table that has:
"Vehicles" 

   Car     |      Options
   --------------------
   foo          2,3  (These options are added in CSV, from an array of check boxes upon "Adding" the vehicle initially)

another table that has:
"Vechicle Options:"
ID      |    Interior
-----------------
1       | power windows
2       | heated seats
3       | cruise control

On my page that displayes the vehicle information I want to display all the related options from the "Vehicle Options" table.

I was thinking about an SQL select like:
"SELECT `Interior` FROM `VehicleOptions` WHERE `ID`=9 and `ID`=8 and `ID`=7"

But this isn't going to work. ;)

Thanks for the help!

Link to comment
https://forums.phpfreaks.com/topic/30061-simple-echo-of-data-from-db-help/
Share on other sites

now another question on forming my PHP sql select.

$VechOptions contains: 1,4,6,9,10,12,15

I want to display it now.
something like:


$OptionsQuery = "SELECT 'Interior' FROM VehicleOptions WHERE 'ID' IN (".$VechOptions.")"; //Don't think this is correct.

// Since this is going to just return 1 result, do I need to for loop it? like below

  $OptionsResult = $database->query($OptionsQuery);
    for ($i=0; $i<$OptionsResult->numRows(); $i++) {
    $OptionsAll = $result->fetchRow(DB_FETCHMODE_ASSOC,$i);
    $VechOptions = $OptionsAll['AllOptions'];

    }

I want to then display kinda like:
echo $VechOptions;  // which would show something like: Power Windows Heated Seats Power Windows etc..


--------
Been trying something like this, just getting Object or Array returned. :(


[code]<?php


  $OptionsQuery = "SELECT 'Interior' FROM VehicleOptions WHERE 'ID' IN ($VechOptions)";
  //SELECT `Interior` FROM `VehicleOptions` WHERE `ID` IN (9,6,4)
  $OptionsResult = $database->query($OptionsQuery);
  echo $OptionsResult;

//  for ($i=0; $i<$OptionsResult->numRows(); $i++) {
    $OptionsAll = $result->fetchRow(DB_FETCHMODE_ASSOC,$i);
    $VechOptions = $OptionsAll['AllOptions'];
     
echo $VechOptions[0].' '.'<BR>';


    }[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.