Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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