View Full Version : mysql to variable
Roost3r
09-23-2002, 03:07 AM
how do i get a mysql value into a variable... i tried
$titles = mysql_query("SELECT title FROM news ORDER BY ID DESC",$db);
$PageArray = explode("\n", $titles);
$PageArray[0];
instead of showing the value its showing "Resource id #3"
when i use $PageArray[1] or more its blank
in my title is "title1\n title2\n title3"
you can see for yourself what its doing here http://xtremehw.com/reviews.php
firepages
09-23-2002, 09:02 AM
$titles is just a pointer to the result set, you still have to fetch the row....
<?
$titles = mysql_query("SELECT title FROM news ORDER BY ID DESC",$db);
//this fetches the row data//
$pa=mysql_fetch_row($titles);
//$pa[0] is the first (and here only) returned field//
$PageArray = explode("\n", $pa[0]);
echo $PageArray[0];
?>
Roost3r
09-23-2002, 03:34 PM
it works when i use your example
but when i use your example and use 1 instead of 0 nothing comes on the screen
i get the same thing described in my first post
i need all the info to be set to the pageArray; not just the first part; and the amount of titles will vary
firepages
09-23-2002, 04:59 PM
"SELECT *FROM news ORDER BY ID DESC"
now $PageArray[0] will hold the first field $PageArray[1] the second etc.
you can also use mysql_fetch_array() in which case $PageArray['title'] would hold the title field
also check out mysql_fetch_object() in the manual , if you have not got the manual get it as it holds pretty much all the answers http://www.php.net
Roost3r
09-23-2002, 07:17 PM
im already using mysql_fetch_array() or mysql_fetch_row()
heres what im using now which doesnt display the title how i want it to; everything else is displayed fine
<?php
$db = mysql_connect("localhost");
mysql_select_db("cklepeis_xhdb",$db);
$titles = mysql_query("SELECT title FROM news",$db);
$pa = mysql_fetch_row($titles);
$myArray = explode("\n", $pa[0]);
$news = mysql_query("SELECT id, postedOn, body FROM news ORDER BY ID DESC",$db);
$newsadv = 0;
while ($myrow = mysql_fetch_row($news)) {
echo "<tr>";
if ($newsadv >= 3) {
echo "<td colspan=2>";
} else {
echo "<td>";
}
printf("<a href=\"?newsid=%s&p=1\" class=\"title\"><b><u> %s </u>
</b></a> <font id=\"date\"> - %s</font>", $myrow[0], $myArray[0], $myrow[1]);
printf(" %s", $myrow[2]);
echo "<hr color=#999999 width=90%>";
echo "</td>";
if ($newsadv == 0) {
echo "<td rowspan=3 width=160 valign=top><img src=\"./images/adv.gif\"></td>";
}
echo "</tr>";
$newsadv++;
}
?>
i dont think you understand what im trying to do... i have to parse the info in my "titles" field to a array of x size; i can already get the rest of the stuff in my other fields displayed; thats not the problem
Roost3r
09-23-2002, 10:26 PM
i change the "\n" spacer for explode; i guess it doesnt like \n
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.