Jump to content

Variable and array


ecabrera

Recommended Posts

How would i make the test variable an array so once it's an array i can do a foreach loop so i can use suffle

 

		  	<?php
require "admin/scripts/connect.php";

$newquery = mysql_query("SELECT * FROM test WHERE live=1");

do{
$test = stripslashes($row['message']);
$f = stripslashes($row['firstname']);
$l = strtoupper(stripslashes($row['lastname']));
echo "<p align='justify'>$test</p>";
echo "<h4 align='right'>$f.$l</h4>";

}while($row = mysql_fetch_assoc($newquery));




mysql_close();
?>

Link to comment
Share on other sites

while($row = mysql_fetch_assoc($newquery)){
// you are looping through it now, and can access the data as if $row was an array with the various field names as keys.
}

http://php.net/manual/en/function.mysql-fetch-assoc.php

 

You can decide to put it all organized into some array when you are looping through the results row by row. Maybe there is some id you get from the result that you want to identify the data by.

 

$array = array();
while($row = mysql_fetch_assoc($newquery)){
$array[$row['id']] = $row;
}
foreach($array AS $rows=>$key){
// whatever
}

 

sorry if there are any typos... (haven't slept in over a day :P)

Link to comment
Share on other sites

Thanks for helping me im on the 24 coding so tried but have to finish so what i want to do is make a testimonial box that will display each testimonial separate but in order to do that i will have to make it a array

 

$test[] = stripslashes($row['message']);
$f = stripslashes($row['firstname']);
$l = strtoupper(stripslashes($row['lastname']));
foreach($test AS $messages){
echo "<p align='justify'>$messages</p>";
}

echo "<h4 align='right'>$f.$l</h4>";

}

 

but some how its showing duplicate's i dont understand

Link to comment
Share on other sites

ok so that work but one problem that i dont understand is can the message from that user how would i get there fristname also i tried this but nothing

foreach($test AS $messages){
echo "<p align='justify'>$messages</p>";
foreach($f as $first)
{
echo "<h4 align='right'>$first</h4>";
}
}

 

unless this might work

 

 

foreach($test AS $messages){
echo "<p align='justify'>$messages</p>";
foreach($message as $first)
{
echo "<h4 align='right'>$first</h4>";
}
}

 

Link to comment
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.