Jump to content

explode and SQL


Recommended Posts

Hey guys me (again) lol

 

Out of interest is it possible to explode a mysql_fetch_array.

 

What I've done is used 4 mysql queries to select 4 random rows and just echo'd them but I really want to cut the code up and make it something I can explode and echo as a set variable.

 

can I do this?

Link to comment
https://forums.phpfreaks.com/topic/105779-explode-and-sql/
Share on other sites

do you mean

<?php
$username = $row['username'];
$password = $row['password'];
$etc = $row['etc'];

//or
extract($row);

//or
foreach($row as $k => $v)
{
$$k = $v;
}

//or
list($username, $password, $ect) = $row;
?>

 

all do the same

 

Not quite.

 

extract() requires an associative array (eg from mysql_fetch_assoc() )

 

list() requires an indexed array (eg from mysql_fetch_row() )

Link to comment
https://forums.phpfreaks.com/topic/105779-explode-and-sql/#findComment-542190
Share on other sites

Lol, basically I need to query the database and get 4 random rows, which I can then on an external page echo as 4 differant products.

 

Laid out like this,

 

 

$var_1_pic$var_2_pic$var_3_pic$var_4_pic

$var_1$var_2$var_3$var_4

 

 

pic obviously meaning a picture name I have in the database I'm not really that good with SQL implementation thus I'm stuck I dont really want to have to write out a differant query 4 times when I know I can explode the result of a query and assign it to differant variables.

Link to comment
https://forums.phpfreaks.com/topic/105779-explode-and-sql/#findComment-542823
Share on other sites

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.