Jump to content

PHP Help


Elton

Recommended Posts

The code below can be seen in action at http://www.select-imports.org/

 

Basically, it's the code that displays the latest 10 listings on the site.

 

The owners have decided that they'd like to do away with the text on the front page and have all of their cars listed on the front page, in 3 or four columns. Can anyone tell me where and how I start hacking this to accomodate their wishes?

 

tia,

 

Elton

Anglers' Net Shopping Partners - Please Support Your Forum

CLICK HERE for all your Amazon purchases - books, photography equipment, DVD's and more!

CLICK HERE for Go Outdoors. HUGE discounts!

 

FOLLOW ANGLERS' NET ON TWITTER- CLICK HERE - @anglersnet

PLEASE 'LIKE' US ON FACEBOOK - CLICK HERE

Link to comment
Share on other sites

// Newest Listings Code.

// This code will display the last five listings added.

 

//setup the database

$link = mysql_connect ($dbserver, $dbuser, $dbpassword);

if (! $link)

{

die ("$L_noConnect");

}

if (!mysql_select_db ($db, $link) )

{

die ("Couldn't open $db: ".mysql_error() );

}

$sql = "SELECT v_id, id, year, make , model, price FROM vehicles ORDER BY v_id DESC LIMIT 0,10";

// You can change the 5 in the above statement to whatever number you want to display.

 

$sql_result = mysql_query($sql,$link) or die ("Couldn't execute Query!");

 

if (!$sql_result) {

echo "

Couldn't get List";

}else{

 

// This section prints the display. You may adjust it to fit your needs.

// You can use all the variables defined in the while loop below.

 

echo "





";

while ($row = mysql_fetch_array($sql_result)) {
$v_id = $row["v_id"];
$id = $row["id"];
$year = $row["year"];
$make = $row["make"];
$model = $row["model"];
$price = $row["price"];
$stock_id = stripslashes($stock_id);
$year = stripslashes($year);
$model = stripslashes($model);
$vin = stripslashes($vin);
$price = stripslashes($price);
$price = number_format ($price);
$count = $count + 1;

$img_chk = "SELECT filesize FROM thumb_images WHERE img_id = "$id"";
$img_chk_result = mysql_query($img_chk,$link) or die ("Couldn't execute query");
$row5 = mysql_fetch_array($img_chk_result);
$img = $row5["filesize"];
if ($img > 0){
$item_thumb = "show_thumb.php?id=$id";
}else{
$item_thumb = "$baseurl$no_thumb";
}

echo "


";
}

echo "

Latest 10 Listings
$L_clickPic
$item_thumb $year
$make
$model

 

";

}

?>

Anglers' Net Shopping Partners - Please Support Your Forum

CLICK HERE for all your Amazon purchases - books, photography equipment, DVD's and more!

CLICK HERE for Go Outdoors. HUGE discounts!

 

FOLLOW ANGLERS' NET ON TWITTER- CLICK HERE - @anglersnet

PLEASE 'LIKE' US ON FACEBOOK - CLICK HERE

Link to comment
Share on other sites

Think I may be getting somewhere....

 

By duplicating the table above and changing the 0,10 to 11,10, I get another column with the next ten cars. Just need to remove all the repeated text and away we go, I think.

Anglers' Net Shopping Partners - Please Support Your Forum

CLICK HERE for all your Amazon purchases - books, photography equipment, DVD's and more!

CLICK HERE for Go Outdoors. HUGE discounts!

 

FOLLOW ANGLERS' NET ON TWITTER- CLICK HERE - @anglersnet

PLEASE 'LIKE' US ON FACEBOOK - CLICK HERE

Link to comment
Share on other sites

You could`ve used

 

code:

$sql = "SELECT * FROM vehicles ORDER BY v_id DESC LIMIT 0,10";

instead of

 

code:

$sql = "SELECT v_id, id, year, make , model, price FROM vehicles ORDER BY v_id DESC LIMIT 0,10";

Because you`re querying the SQL table like this

code:

while ($row = mysql_fetch_array($sql_result)) { 

$v_id = $row["v_id"];

$id = $row["id"];

$year = $row["year"];

$make = $row["make"];

$model = $row["model"];

$price = $row["price"];

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We and our partners use cookies on our website to give you the most relevant experience by remembering your preferences, repeat visits and to show you personalised advertisements. By clicking “I Agree”, you consent to the use of ALL the cookies. However, you may visit Cookie Settings to provide a controlled consent.