Marcusw
asked on
PHP Array Looping using data from MYSQL
how can i handle data from a table in mysql with php
i have a connection to a database
and i want to have a query that returns set number of records with 5 fields.
ID, Title, Article, Link, Picture
i then want to use these records on my page.
i.e.
Picture - Title
Article
Link
i have wrote the following but don't seem to be getting very far on writing a loop to print the data on the page
require("Conn.php");
$sql = 'SELECT ID, Title,Article,Picture,Link FROM tblArticles LIMIT 10';
$result = mysql_db_query($db1, $sql) or die ("Could not execute query");
$row = mysql_fetch_array($result) ;
thanks
i have a connection to a database
and i want to have a query that returns set number of records with 5 fields.
ID, Title, Article, Link, Picture
i then want to use these records on my page.
i.e.
Picture - Title
Article
Link
i have wrote the following but don't seem to be getting very far on writing a loop to print the data on the page
require("Conn.php");
$sql = 'SELECT ID, Title,Article,Picture,Link
$result = mysql_db_query($db1, $sql) or die ("Could not execute query");
$row = mysql_fetch_array($result)
thanks
actually .. you need to loop through
require("Conn.php");
$sql = 'SELECT ID, Title,Article,Picture,Link FROM tblArticles LIMIT 10';
$result = mysql_db_query($db1, $sql) or die ("Could not execute query");
while($row = mysql_fetch_array($result) ;)
{
echo $row("ID")
echo $row("Title")
echo $row("Article")
echo $row("Picture")
echo $row("Link")
}
}
require("Conn.php");
$sql = 'SELECT ID, Title,Article,Picture,Link
$result = mysql_db_query($db1, $sql) or die ("Could not execute query");
while($row = mysql_fetch_array($result)
{
echo $row("ID")
echo $row("Title")
echo $row("Article")
echo $row("Picture")
echo $row("Link")
}
}
one to many closing brackets .. so remove one }
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ZSoderquist beat me to it =)
<?php
$conn = mysql_connect("localhost", "root", "");
mysql_select_db("DBNAME");
$sql = "SELECT ID, Title,Article,Picture,Link FROM tblArticles LIMIT 10";
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
$numofrows=mysql_num_rows( $result);
if($numofrows>0)
{
while($row=mysql_fetch_arr ay($result ))
{
$ID=$row['ID'];
$Title=$row['Title'];
$Article=$row['Article'];
$Link=$row['Link'];
$Picture=$row['Picture'];
echo $Picture."-".$ID."-".$Titl e."<br>".$ Article."< br>".$Link ."<br><br> ";
}
}
Regards,
M.Raja
$conn = mysql_connect("localhost",
mysql_select_db("DBNAME");
$sql = "SELECT ID, Title,Article,Picture,Link
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
$numofrows=mysql_num_rows(
if($numofrows>0)
{
while($row=mysql_fetch_arr
{
$ID=$row['ID'];
$Title=$row['Title'];
$Article=$row['Article'];
$Link=$row['Link'];
$Picture=$row['Picture'];
echo $Picture."-".$ID."-".$Titl
}
}
Regards,
M.Raja
$sql = 'SELECT ID, Title,Article,Picture,Link
$result = mysql_db_query($db1, $sql) or die ("Could not execute query");
$row = mysql_fetch_array($result)
echo $row("Title")
echo $row("Article")
echo $row("Picture")