Jump to content

MySql Array


Recommended Posts

ok so i want to get certain text from a mysql database.
so far i have done this with this code:
[code]<?php
//this file includes my passwords...etc. used for connecting.
include(config.php);

$db = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

//select "Cmessage" and "csubject" from the list, 2 tables that include data
$query  = "SELECT csubject, cmessage FROM list";
$result = mysql_query($query) or die('Error, query failed ##1');

while($row = mysql_fetch_row($result))
{
    $Subject    = $row[0];
    $Message = $row[1];

// define table codes for the subject place for before and after the text
    $htmlsubbefore="<div class=\"ts hazardrow\"><div class=\"coltitle_dark tlarge\">";
    $htmlsubafter="</div><div style=\"clear:both\"></div></div>";

//define table codes for the message body place before and after the text
    $htmlbodbefore="<table width=\"50%\"><tr class=\"hazardrow\"><td width=\"50%\">";
    $htmlbodafter="</td></tr>";

and then display it with the html before + the row + the HTML after
    echo $htmlsubbefore . $row[0] . $htmlsubafter.
        $htmlbodbefore . $row[1] . $htmlbodafter;

}
?>[/code]

now i'l be honest i'm not that good with MySql sync with php but i  am pretty good with PHP.
i followed a tutorial that got me this far.

anyway, now onto the question. here is what i want to do:
i am basically making a blog. i want to:
1) see how many entries their are
2) set that as the array end
3) keep displaying the different blog entries until there are no more

i hope i explained that in a way you can get. but right now it only displays 1 entry. their are more in the database. how can i keep displaying them with the html tables too? and i don't want it to be a set number because i don't know how many their are going to be
Link to comment
Share on other sites

change this:

while($row = mysql_fetch_row($result))
{
    $Subject    = $row[0];
    $Message = $row[1];

to this:
while($row = mysql_fetch_array($result))
{
    $Subject    = $row['csubject'];
    $Message = $row['cmessage'];


that should get what u want.
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.