PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pookie62
Forum Commoner
Posts: 92 Joined: Tue Dec 07, 2004 2:44 pm
Post
by pookie62 » Tue Dec 28, 2004 12:04 pm
Hi,
I was playing around with printf and tried this:
Code: Select all
<?php
$format = 'Results for %1 held %1 at %3';
printf($format,$w-naam,$date,$location);
?>
Just gave me output like this :
Results for held at
What is wrong with this code?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Dec 28, 2004 12:16 pm
the control values in [php_man]printf()[/php_man] are for type casting, they do not use numbers for anything other than alignment.
pookie62
Forum Commoner
Posts: 92 Joined: Tue Dec 07, 2004 2:44 pm
Post
by pookie62 » Tue Dec 28, 2004 12:20 pm
Hm oke, well I tried to echo this line as well
$w-naam,$date,$location);
but I couldn't get that either right..
..I know, I'm a real newbie.. sorry
How should I echo tthat line ?
Thanks for you quick reply !
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Dec 28, 2004 12:37 pm
there's the echo way:
Code: Select all
echo "Results for $w_naam held $w_naam at $location";in order to tell you what to use for printf, I'd need to know the types those variables are.
pookie62
Forum Commoner
Posts: 92 Joined: Tue Dec 07, 2004 2:44 pm
Post
by pookie62 » Tue Dec 28, 2004 12:43 pm
Thanks feyd !
These are two text fields ; $w_naam and $w_location
The other is date field: $w_date
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Dec 28, 2004 12:46 pm
Code: Select all
printf('Results for %s held %s at %s', $w_naam, $w_date, $w_location);
pookie62
Forum Commoner
Posts: 92 Joined: Tue Dec 07, 2004 2:44 pm
Post
by pookie62 » Tue Dec 28, 2004 12:55 pm
Thanks for your help feyd, but both options only output the first $ ($w_naam) Other $ are not displayed at all.. ??
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Dec 28, 2004 1:03 pm
make sure the variable names are correct.. turn on full error and warning displays and such...
pookie62
Forum Commoner
Posts: 92 Joined: Tue Dec 07, 2004 2:44 pm
Post
by pookie62 » Tue Dec 28, 2004 1:12 pm
Let me post more of my code, you'll probably see right away where the mistake is..
Code: Select all
<?php
while ($row = mysql_fetch_assoc($result))
{
$wedstrijdnaam[] = $row['Naam'];
$w_datum[] = $row['Datum'];
$w_plaats[] = $row['plaats'];
}
/*Similarly for your other drop-down list boxes
$wedstrijdnaam[] = $wedstrijdnaam;
$wedstrijdnaam[] = 'Wedstrijd 2';
$wedstrijdnaam[] = 'Wedstrijd 3';
/*
$genre_names[] = 'Genre 1';
$genre_names[] = 'Genre 2';
$genre_names[] = 'Genre 3';
*/
if (true === isset($_POST['Search']))
{
$where_clause = '';
// handle search
if (true === isset($_POST['Naam']))
{
// Check for search by Wedstrijd
$w_naam = $_POST['Naam'];
if (0 < strlen($w_naam))
{
$where[] = ' Naam = ''' . $w_naam . '''';
}
/* check for search by genre
$g_name = $_POST['genre_name'];
if (0 < strlen($g_name))
{
$where[] = ' genre_name = ''' . $g_name . '''';
}
*/
if (true === is_array($where))
{
$where_clause = implode(' AND ', $where);
}
}
/*
build your query to search the appropriate talbe(s)
and add the $where_clasuse to it, something like */
//<center><b><strong><font size="6" color="#FFFFFF"><?php echo 'Uitslag van ' . $w_naam; </font></strong></b></center>
//echo "Results for $w_naam held $w_datum at $w_plaats";
printf('Results for %s held %s at %s', $w_naam, $w_datum, $w_plaats);
}
?>
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Tue Dec 28, 2004 1:55 pm
$w_datum and $w_plaats are arrays... and you are trying to pass them to a function that is not expecting arrays....
pookie62
Forum Commoner
Posts: 92 Joined: Tue Dec 07, 2004 2:44 pm
Post
by pookie62 » Tue Dec 28, 2004 2:06 pm
Oke, understand.. how can I solve this ?
I got a similair issue in another script, would be very happy to see an example how to do this.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Dec 28, 2004 4:48 pm
using any one of the looping controls and iterating through the array printing them out in the format you wish, or using some of the built-in array printing functions... ([php_man]print_r()[/php_man])
pookie62
Forum Commoner
Posts: 92 Joined: Tue Dec 07, 2004 2:44 pm
Post
by pookie62 » Wed Dec 29, 2004 2:56 am
How would I implement this in my code ?
I read the print_r article but it looks to me that the whole aray is echo-ed.
Could you please provide a few lines of code how to uset his ?
Thanks !
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Wed Dec 29, 2004 3:21 am
Straight from Manual...
Code: Select all
<pre>
<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>
</pre>
Which will output:
<pre>
Array
(
їa] => apple
їb] => banana
їc] => Array
(
ї0] => x
ї1] => y
ї2] => z
)
)
</pre>
I hope that helps u a bit...
Lemme know...
Bye 4 now!
pookie62
Forum Commoner
Posts: 92 Joined: Tue Dec 07, 2004 2:44 pm
Post
by pookie62 » Wed Dec 29, 2004 3:30 am
I saw this example, but still don't understand how to use it it the code that I posted.. I'm real newbie so...
How must I use in this line ??
Code: Select all
<?php
echo "Results for $w_naam held $w_naam at $location";
?>