Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Str_Replace With Arrays
Old 02-17-2008, 04:22 AM Str_Replace With Arrays
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
I run the following script and i get this error message. I would like to delete the team that is generated by the while so i used str_replace and set it to "".

Error:
PHP Code:
Warning:  array_rand() [function.array-rand]: First argument has to be an array in /home/champion/public_html/fixtures3.php on line 36 
Code:
PHP Code:
function fixtures2($league_id)
{
mysql_query("TRUNCATE TABLE `manager__fixtures`"); 

$match_day 0;
while(
$match_day 19)
{
$match_day++;
echo 
"<strong>Match Day: $match_day</strong><br /><br />";
$clubs mysql_query("SELECT * FROM `manager__teams` WHERE `league` = '$league_id' LIMIT 20");
while(
$row2 mysql_fetch_array($clubs)) {
// Generate List Of Teams In League
$teams mysql_query("SELECT * FROM `manager__teams` WHERE `league` = '$league_id' LIMIT 20");
while(
$row mysql_fetch_row($teams)) {
$myArray[$row[0]] = $row[1];
}
// Delete Teams From List Who Are Already Playing
$fixtures mysql_query("SELECT * FROM `manager__fixtures` WHERE `league` = '$league_id' && `match_day` = '$match_day' LIMIT 20");
while(
$fixtures2 mysql_fetch_array($fixtures))
{
$home mysql_fetch_array(mysql_query("SELECT * FROM `manager__teams` WHERE `id` = '" $fixtures['home_team'] . "' LIMIT 1"));
$away mysql_fetch_array(mysql_query("SELECT * FROM `manager__teams` WHERE `id` = '" $fixtures['away_team'] . "' LIMIT 1"));

$replace str_replace($home['team'], ""$myArray);
$replace str_replace($away['team'], ""$replace);
}
// Delete Teams From List Who Have Already Played At This Team
$fixtures1 mysql_query("SELECT * FROM `manager__fixtures` WHERE `league` = '$league_id' && `match_day` = '$match_day' && `home_team` = '" $row2['id'] . "' LIMIT 20");
while(
$fixtures2 mysql_fetch_array($fixtures1))
{
$replace str_replace($fixtures2['away_team'], ""$replace);
}
// Pick Team To Play

$random array_rand($replace);
$team $replace[$random];

$id mysql_fetch_array(mysql_query("SELECT * FROM `manager__teams` WHERE `team` = '$team' LIMIT 1"));

mysql_query("INSERT INTO `manager__fixtures` ( `id` , `home_team` , `away_team` , `date` , `type`, `league`, `match_day` ) VALUES ('', '" $row2['id'] . "', '" $id['id'] . "', '0', 'League', '$league_id', '$match_day')");


// Show Results
echo "<strong>" $row2['id'] . "</strong> <br />" print_r($myArray) . "<br /><br />";

}
}
}
echo 
fixtures2("2"); 
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 02-17-2008, 12:41 PM Re: Str_Replace With Arrays
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
*Looks at line 36*
PHP Code:
$random array_rand($replace); 
I would assume, $replace is not an array. the best fix I can give you is:
PHP Code:
if(is_array($replace)){
$random array_rand($replace);
// do rest of script.
} else {
// say an error occurred. 

So your script should look something like:

PHP Code:
function fixtures2($league_id)
{
mysql_query("TRUNCATE TABLE `manager__fixtures`"); 

$match_day 0;
while(
$match_day 19)
{
$match_day++;
echo 
"<strong>Match Day: $match_day</strong><br /><br />";
$clubs mysql_query("SELECT * FROM `manager__teams` WHERE `league` = '$league_id' LIMIT 20");
while(
$row2 mysql_fetch_array($clubs)) {
// Generate List Of Teams In League
$teams mysql_query("SELECT * FROM `manager__teams` WHERE `league` = '$league_id' LIMIT 20");
while(
$row mysql_fetch_row($teams)) {
$myArray[$row[0]] = $row[1];
}
// Delete Teams From List Who Are Already Playing
$fixtures mysql_query("SELECT * FROM `manager__fixtures` WHERE `league` = '$league_id' && `match_day` = '$match_day' LIMIT 20");
while(
$fixtures2 mysql_fetch_array($fixtures))
{
$home mysql_fetch_array(mysql_query("SELECT * FROM `manager__teams` WHERE `id` = '" $fixtures['home_team'] . "' LIMIT 1"));
$away mysql_fetch_array(mysql_query("SELECT * FROM `manager__teams` WHERE `id` = '" $fixtures['away_team'] . "' LIMIT 1"));

$replace str_replace($home['team'], ""$myArray);
$replace str_replace($away['team'], ""$replace);
}
// Delete Teams From List Who Have Already Played At This Team
$fixtures1 mysql_query("SELECT * FROM `manager__fixtures` WHERE `league` = '$league_id' && `match_day` = '$match_day' && `home_team` = '" $row2['id'] . "' LIMIT 20");
while(
$fixtures2 mysql_fetch_array($fixtures1))
{
$replace str_replace($fixtures2['away_team'], ""$replace);
}
// Pick Team To Play

if(is_array($replace)){
$random array_rand($replace);
$team $replace[$random];

$id mysql_fetch_array(mysql_query("SELECT * FROM `manager__teams` WHERE `team` = '$team' LIMIT 1"));

mysql_query("INSERT INTO `manager__fixtures` ( `id` , `home_team` , `away_team` , `date` , `type`, `league`, `match_day` ) VALUES ('', '" $row2['id'] . "', '" $id['id'] . "', '0', 'League', '$league_id', '$match_day')");


// Show Results
echo "<strong>" $row2['id'] . "</strong> <br />" print_r($myArray) . "<br /><br />";
} else {
echo 
"Sorry, nothing to show :(";
}
}
}
}
echo 
fixtures2("2"); 
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 02-17-2008 at 12:44 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Reply     « Reply to Str_Replace With Arrays
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10731 seconds with 12 queries