PHP Help needed

Status
Not open for further replies.

rrahman

New Member
2
2012
0
0
Hello all PHP developer.

I need a help to solve my problem.

<?php
include_once("connect.php");

$sql = "Select * from news LIMIT 2";
$r = mysql_query($sql);

$view = "";
while($n = mysql_fetch_array($r))
{
$id = $n['id'];
$title = $n['title'];
$view .= $title;
}

?>

Here are 2 data in $view. now I want to get that 2 data (included in $view) in 2 different variable...
 
3 comments
Instead of appending data to the $view string, put it in an array, like
PHP:
<?php
//= Query ========================//
$sql=mysql_query("select * from table1");

//= Closed while ====================//
/*everytime it fetches the row, adds it to array...*/
while($r[]=mysql_fetch_array($sql));

echo "<pre>";
//= Prints $r as array =================//
print_r ($r);
//=============================//
echo "</pre>";
?>
from php.net mysql_fetch_array().
 
Status
Not open for further replies.
Back
Top