[OOP/MySQLi] Streaming data from database

Status
Not open for further replies.

brsy

nah mang
May 12, 2011
1,530
272
I am creating a site where I can share stuff like my progress on projects, give demo's, etc. Basically I am creating the projects page right now, and I need a little help. I rather have the data in a database then having to edit the file over and over. So can something like this work?
PHP:
<?php include("includes/config.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>zTriick.com | OOP Testing</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
<div class="header">
<div class="headercontent">
<div class="menu"><a href="/index">Home</a> | <a href="#prjs">Tests</a> | <a href="http://devbest.com/members/ztriick.2912/">DevBest</a></div><div class="logo">zTriick.com</div>
  </div>
</div>
<?php
$sql = $mysqli->query("SELECT * FROM projects");
?>
<div class="container">
    <div class="prjs">
        <div class="headertitle"></div>
            <div class="content"></div>
How would I possibly go about streaming the title which would go in the "<div class="headertitle"></div>" and the content to go in "<div class="content"></div>"?

Demo Link:
 

brsy

nah mang
May 12, 2011
1,530
272
But how would I manage to show three different projects? If I do echo $sql[prjName]; for each project column, wouldn't it show the same project over and over?
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
Don't listen to Powahcoder, he doesn't know what he's talking about.

PHP:
while($row = $sql->fetch_object()) 
{
     echo $row['prjName'];
}

Think it should work, double checked with an example on
 

brsy

nah mang
May 12, 2011
1,530
272
Don't listen to Powahcoder, he doesn't know what he's talking about.

PHP:
while($row = $sql->fetch_object())
{
    echo $row['prjName'];
}

Think it should work, double checked with an example on
No, it didn't work for me. Here's all the code I had:
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>zTriick.com | OOP Testing</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
 
<?php include('temp/navi.php');
include('includes/config.php');
$sql = $mysqli->query('SELECT * FROM projects');
while($row = $sql->fetch_object());
?>
 
<div class="container">
    <div align="center">
    <div class="left">
        <div class="headertitle">Featured Projects</div>
            <div class="content">Here are a few projects created by close friends and/or I. Well basically IPie :)</div></div>
 
    <div class="right">
        <div class="headertitle">Advertisements</div>
            <div class="content"><i>There are no adverts at this time.</i>
<br />
Please contact <strong>[email protected]</strong> to get your ad listed here.</div>
</div>
<div class="left">
<div class="headertitle"><?php echo $row['header']; ?></div>
<div class="content"><?php echo $row['content']; ?></div></div>
    </div>
<div class="footer">Copyright &copy 2011<strong> zTriick</strong>
<br />Design by <strong>Retroa</strong>
</div></div>
</body>
</html>

-------------------------------------------------
Here's what happens:
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
facepalm.jpg

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>zTriick.com | OOP Testing</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
 
<?php include('temp/navi.php');
include('includes/config.php');
$sql = $mysqli->query('SELECT * FROM projects');
while($row = $sql->fetch_object())
{
?>
 
<div class="container">
    <div align="center">
    <div class="left">
        <div class="headertitle">Featured Projects</div>
            <div class="content">Here are a few projects created by close friends and/or I. Well basically IPie :)</div></div>
 
    <div class="right">
        <div class="headertitle">Advertisements</div>
            <div class="content"><i>There are no adverts at this time.</i>
<br />
Please contact <strong>[email protected]</strong> to get your ad listed here.</div>
</div>
<div class="left">
<div class="headertitle"><?php echo $row['header']; ?></div>
<div class="content"><?php echo $row['content']; ?></div></div>
    </div>
<?php } ?>
<div class="footer">Copyright &copy 2011<strong> zTriick</strong>
<br />Design by <strong>Retroa</strong>
</div></div>
</body>
</html>
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,926
3,921
facepalm.jpg

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>zTriick.com | OOP Testing</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
 
<?php include('temp/navi.php');
include('includes/config.php');
$sql = $mysqli->query('SELECT * FROM projects');
while($row = $sql->fetch_object())
{
?>
 
<div class="container">
    <div align="center">
    <div class="left">
        <div class="headertitle">Featured Projects</div>
            <div class="content">Here are a few projects created by close friends and/or I. Well basically IPie :)</div></div>
 
    <div class="right">
        <div class="headertitle">Advertisements</div>
            <div class="content"><i>There are no adverts at this time.</i>
<br />
Please contact <strong>[email protected]</strong> to get your ad listed here.</div>
</div>
<div class="left">
<div class="headertitle"><?php echo $row['header']; ?></div>
<div class="content"><?php echo $row['content']; ?></div></div>
    </div>
<?php } ?>
<div class="footer">Copyright &copy 2011<strong> zTriick</strong>
<br />Design by <strong>Retroa</strong>
</div></div>
</body>
</html>
He's fetching an object, not an array.

It would be:
PHP:
$sql = $mysqli->query('SELECT * FROM projects');
 
while($row = $sql->fetch_object()) {
 
    echo $row->content;
    echo $row->header;
 
}
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
He's fetching an object, not an array.

It would be:
PHP:
$sql = $mysqli->query('SELECT * FROM projects');
 
while($row = $sql->fetch_object()) {
 
    echo $row->content;
    echo $row->header;
 
}

Woops, true that.

Soo, just do..

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>zTriick.com | OOP Testing</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
 
<?php include('temp/navi.php');
include('includes/config.php');
$sql = $mysqli->query('SELECT * FROM projects');
while($row = $sql->fetch_object())
{
?>
 
<div class="container">
    <div align="center">
    <div class="left">
        <div class="headertitle">Featured Projects</div>
            <div class="content">Here are a few projects created by close friends and/or I. Well basically IPie :)</div></div>
 
    <div class="right">
        <div class="headertitle">Advertisements</div>
            <div class="content"><i>There are no adverts at this time.</i>
<br />
Please contact <strong>[email protected]</strong> to get your ad listed here.</div>
</div>
<div class="left">
<div class="headertitle"><?php echo $row->header; ?></div>
<div class="content"><?php echo $row->content; ?></div></div>
    </div>
<?php } ?>
<div class="footer">Copyright &copy 2011<strong> zTriick</strong>
<br />Design by <strong>Retroa</strong>
</div></div>
</body>
</html>

:oops:
 
Status
Not open for further replies.

Users who are viewing this thread

Top