Forum Moderators: coopster

Message Too Old, No Replies

mysql_fetch_array() with MYSQL_BOTH

too many or not enough "" ' '

         

henry0

9:48 pm on May 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is what I have
I need to respect the $content format
which allows me to display content within an O O template system

I cannot make working the ("Home Page: %s Newsletter: %s", $new_content["url"], $new_content["newsletter"]);

I am looking for Home Page +corresponding result to appear in a sequence then the Newsletter....
<<<
<?
$conn = db_connect();
$sql= "select url, newsletter from group_1 where id=$id";
$result = mysql_query($sql,$conn);
while ($new_content=mysql_fetch_array($result,MYSQL_BOTH) )
{
$content_5.= ("Home Page: %s Newsletter: %s", $new_content["url"], $new_content["newsletter"]);
}
?>

regards

Henry

jatar_k

6:33 am on May 4, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



did you figure this out henry?

$content_5.= ("Home Page: %s Newsletter: %s", $new_content["url"], $new_content["newsletter"]);

I am not sure what the parentheses are all about but it almost looks like you forgot

sprintf

or something similar

henry0

12:27 pm on May 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Jatar_K

not sure if I need "Sprintf" or any other flavor
[edit] of course if I use printf and do not use $content_5 I then display the right content but it goes out of the templating system and sit atop the page in the browser instead of where I want it located
[/edit]
here is what I have in my OO system
(I pass on the class)
FROM INDEX:
$content_1 .= '';
include "includes/late_nav.inc.php";
$page->SetParameter("LATE_NAV", $content_1);

FROM MAIN_TEMPLATE:
<tr><td>
<div class="late_nav">
<!--{LATE_NAV}-->
</div>
</tr></td>

and here is an example of "includes/****.inc.php"
that does the job without printf
<?
$conn = db_connect();
$sql= "select biz_present from group_1
where id=$id";
$result = mysql_query($sql,$conn);
while ($new_content=mysql_fetch_array($result) ){
$content_5.= $new_content[biz_present];
}
?>

the question is: do I need to use always a printf or other when using MYSQL_BOTH

so we are back to making that line working
{
$content_5.= ("Home Page: %s Newsletter: %s", $new_content["url"], $new_content["newsletter"]);
}

thank you

Henry

henry0

2:59 pm on May 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well ..Done
in order to keep $content base I did

{
$content_5.=sprintf ("Home Page: %s Newsletter: %s", $new_content["url"], $new_content["newsletter"]);
}

so it's a combo of my previous $content_5 and printf

Henry

jatar_k

5:15 pm on May 4, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you don't need to use printf all the time but the original syntax was just wrong, it looked like if you just missed the printf and if you dropped it in it would work as is.

this works

$content_5.= "Home Page: " . $new_content["url"] . " Newsletter: " . $new_content["newsletter"];

or this
$content_5.= "Home Page: {$new_content['url']} Newsletter: {$new_content['newsletter']}";

think that last one is right. I don't use that format and mess it up sometimes.

henry0

5:35 pm on May 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks
it is more elegant and offers less chance to forget any typing or reverse order
Henry