Skip to content
WJunction - Webmaster Forum

PHP Help needed

Status
Not open for further replies.
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.

About the author

R
New Member · Joined
2
Messages
0
Reactions
1
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom