
Philip
Staff Alumni-
Posts
4,665 -
Joined
-
Last visited
-
Days Won
20
Everything posted by Philip
-
Also, using quotes around the key is good practice - otherwise it'll look for that constant first, then automatically assume 'id' instead. <?php include 'connection.php'; if(!isset($_GET['id']) || empty($_GET['id'])) { // if there was no id in the url, or it was empty kill the script die('Invaild script parameters!'); } $query = "SELECT * FROM `test` WHERE ID = '".$_GET['id']."'"; $result = mysql_query($query); $post = mysql_fetch_array($result); ?> Make sure $_GET['id'] is getting set & has a value.
-
$link = mysql_connect($host, $user, '$password); no { needed, just a ;
-
getting Parse error: syntax error, unexpected T_ELSE in..
Philip replied to Iank1968's topic in PHP Coding Help
Can you post your current code? Here's what I have for you, more organized IMO - also read the comment about the while loop, it should make your code easier <?php function HandleOutstandingSendSuccesses ($user) { global $logsend_table; global $facebook; global $db_to_desc_send; //$rx_money = false; $result = Query ("SELECT id,uid_from,what,amt FROM $logsend_table WHERE uid_to=$user and notified='0' and trade=0"); $num_rows = mysql_num_rows($result); // Why not use mysql_fetch_assoc here instead of the for( ) loop? // Below is an example: /* while($row = mysql_fetch_array($result)) { $uid_from = $row['uid_from']; $what = $row['what']; // ... etc // run your try/catch and messages } // end loop for each row fetched */ for ($i=0; $i<$num_rows; $i++) { $uid_from = mysql_result($result, $i, "uid_from"); $what = mysql_result($result, $i, "what"); $amt = mysql_result($result, $i, "amt"); $id = mysql_result($result, $i, "id"); try { $info = $facebook->api_client->users_getInfo ($uid_from, "name"); } catch (FacebookRestClientException $e) { $info = ""; } //$persons_name = $info[0]['name']; $persons_name = isset ($info[0]['name']) && $info[0]['name'] != "" ? $info[0]['name'] : "Someone"; if ($what == "money") { //$rx_money = true; $amt_f = sprintf ("%.2f", $amt/100); ?> <fb:success message="WOW!!!! <?php echo $persons_name;?> just sent you $<?php echo $amt_f;?> airfarebucks!" /> <?php } else { $prize_f = $db_to_desc_send[$what]; ?> <fb:success message="WOW!!!! <?=$persons_name;?> just sent you <?=$amt;?> of the following prize: <?=$prize_f;?>" /> <?php } Query("UPDATE $logsend_table SET notified=1 where id=$id"); } } // end function function HandleCoupons ($user) { global $users_table; $result = Query ("SELECT sum(coupon1) FROM $users_table WHERE uid=$user and coupon1_notified='0'"); if(mysql_result($result, 0) > 0) { $result_new = Query ("UPDATE $users_table SET coupon1_notified='1' where uid=$user"); } return mysql_result($result, 0); } ?> -
I'd use array_combine() $users = '1;7;5;3;6;2'; $users = explode(";", $users); $points = '10;12;8;11;8;9'; $points = explode(";", $points); $array = array_combine($users, $points); // combine, use users as key, $points as value arsort($array); // sort, maintaining the correct keys, from highest to lowest points echo '<pre>'; print_r($array); // show what outputs echo '</pre>'; Outputs: Array ( [7] => 12 [3] => 11 [1] => 10 [2] => 9 [5] => 8 [6] => 8 )
-
Home Show Booth to advertise Freelance Web Design
Philip replied to amin7b5's topic in Miscellaneous
I think you should do something like if your prospective clients were walking into your code/a webpage. Kinda like http://css-tricks.com/0404 Just a basic idea. -
Why didn't I think of it like that
-
<?php $totalPlayers = 83; // # of people $seatsPerTable = 10; // # of seats at each table $tableNum = ceil($totalPlayers/$seatsPerTable); // # of tables $maxTables = ($totalPlayers%$seatsPerTable); // # of tables that are maxed out $table = array(); // setup table array for($currentTable=1, $currentPlayer=1; $currentTable<=$tableNum; $currentTable++) { // Loop through each table if($currentTable==$maxTables) { // If the current table is equal to the number of tables with max players, // we need to subtract 1 from the seat count on the rest of the tables $seatsPerTable--; } for($currentSeat=1; $currentSeat<=$seatsPerTable; $currentSeat++,$currentPlayer++) { // Loop through each seat $table[$currentTable][$currentSeat] = 'player #'.$currentPlayer; } } $totalSeats = $currentPlayer-1; // We have to adjust for the last loop (still adds 1) // Show results: echo 'Seats used: ',$totalSeats,'<pre>'; print_r($table); echo '</pre>'; ?> Tested. However, not sure if it's what you want though. Just to show output here: Seats used: 83 Array ( [1] => Array ( [1] => player #1 [2] => player #2 [3] => player #3 [4] => player #4 [5] => player #5 [6] => player #6 [7] => player #7 [8] => player #8 [9] => player #9 [10] => player #10 ) [2] => Array ( [1] => player #11 [2] => player #12 [3] => player #13 [4] => player #14 [5] => player #15 [6] => player #16 [7] => player #17 [8] => player #18 [9] => player #19 [10] => player #20 ) [3] => Array ( [1] => player #21 [2] => player #22 [3] => player #23 [4] => player #24 [5] => player #25 [6] => player #26 [7] => player #27 [8] => player #28 [9] => player #29 ) [4] => Array ( [1] => player #30 [2] => player #31 [3] => player #32 [4] => player #33 [5] => player #34 [6] => player #35 [7] => player #36 [8] => player #37 [9] => player #38 ) [5] => Array ( [1] => player #39 [2] => player #40 [3] => player #41 [4] => player #42 [5] => player #43 [6] => player #44 [7] => player #45 [8] => player #46 [9] => player #47 ) [6] => Array ( [1] => player #48 [2] => player #49 [3] => player #50 [4] => player #51 [5] => player #52 [6] => player #53 [7] => player #54 [8] => player #55 [9] => player #56 ) [7] => Array ( [1] => player #57 [2] => player #58 [3] => player #59 [4] => player #60 [5] => player #61 [6] => player #62 [7] => player #63 [8] => player #64 [9] => player #65 ) [8] => Array ( [1] => player #66 [2] => player #67 [3] => player #68 [4] => player #69 [5] => player #70 [6] => player #71 [7] => player #72 [8] => player #73 [9] => player #74 ) [9] => Array ( [1] => player #75 [2] => player #76 [3] => player #77 [4] => player #78 [5] => player #79 [6] => player #80 [7] => player #81 [8] => player #82 [9] => player #83 ) )
-
$insertport is what you're trying to call, it should be $insertpost
-
A great tutorial on our site about pagination: http://www.phpfreaks.com/tutorial/basic-pagination
-
Change: header('Location: http://www.exampleurl.com/files/$filename'); to header('Location: http://www.exampleurl.com/files/'.$filename);
-
Updating cron jobs with php, using cron to execute php script - help!
Philip replied to Chrisynd's topic in PHP Coding Help
Ehh, I would be careful running a script that long. Although the script might be "sleeping" it is still having to use resources, and can cause overload on a server - especially if you're doing it for 60 minutes, every hour (making it run 24/7) -
Updating cron jobs with php, using cron to execute php script - help!
Philip replied to Chrisynd's topic in PHP Coding Help
Depending on if your traffic size is large enough, you could have each page load simply run one or two emails - then whatever is left over, the cron would take care of. -
Updating cron jobs with php, using cron to execute php script - help!
Philip replied to Chrisynd's topic in PHP Coding Help
I wouldn't run it every minute. A lot of hosts (and I'm surprised GoDaddy doesn't do this) limit the crons to every 10-15 minutes. This helps from users overloading their servers by running resource intensive scripts every single freakin' minute. Now, I don't know how to setup a cron job via PHP - in fact I don't know how possible it is running it off a shared host. From what it sounds like, running a cron every 10-15 minutes should be fine. When it's running, just have it look for a message time within the past 10-15 minutes, and then you could delete that row (or set a flag saying message sent) -
[SOLVED] newbie - cant get settype() to work...
Philip replied to nyzwerewolf's topic in PHP Coding Help
and line 2 <?php $undecided = 3.14; echo "Is " .$undecided. " a double? " .is_double($undecided). "<br />"; // double settype ($undecided, 'string'); echo "Is " .$undecided. " a string? " .is_string($undecided). "<br />"; // string settype ($undecided, 'integer'); echo "is " .$undecided. " an integer? " .is_int($undecided). "<br />"; // integer settype ($undecided, 'double'); echo "is " .$undecided. " a double? " .is_double($undecided). "<br />"; // double settype ($undecided, 'bool'); echo "is " .$undecided. " a boolean? " .is_bool($undecided). "<br />"; // boolean ?> Although, I would take a look at this comment -
Well why are you using the user's name as a field in your table....that really makes no sense to me, instead of just having a field called username and storing it there. Anyhow, if KingPhilip's worked, then yea that is how your table is designed. Weird, but I guess it works for you. His table setup is fine, he was just doing: value = column instead of column = value like we are used to seeing
-
'$logged[username]' = 'username' should be `username` = '$logged[username]' column names are always surrounded by backticks (`) and values by single quotes (')
-
[SOLVED] Counting How Many Lines Are Inside Certain Markup Tags.
Philip replied to Vermillion's topic in PHP Coding Help
It's because it returns an array item for each instance of the blocks. So $result = countLines($string); if(isset($result[0]) echo $result[0]; // the above line will show how many lines in the first [code] block if(isset($result[1]) echo $result[1]; // this one shows the second, if it exists... etc.[/code] -
Getting Parse error: syntax error, unexpected '<' in
Philip replied to Iank1968's topic in PHP Coding Help
Post your full code, not just // some php Something in that some php it whats causing your error most likely. -
[SOLVED] concatenate text and variables in php
Philip replied to kevinritt's topic in PHP Coding Help
A few ways: echo 'Hello, ' .$_SESSION['username']. 'it is ' .date('F j, Y'). 'and the time is ' .date('H:i:s'); echo 'Hello, ',$_SESSION['username'],'it is ',date('F j, Y'),'and the time is ',date('H:i:s'); echo "Hello, {$_SESSION['username']} it is ".date('F j, Y')."and the time is ".date('H:i:s'); -
You need to make sure to escape the quotes, <?php $EmailFrom = "[email protected]"; $EmailTo = "[email protected]"; $Subject = "FORM"; $Name = Trim(stripslashes($_POST['Name'])); $Filename = Trim(stripslashes($_POST['Filename'])); $OtherInformation = Trim(stripslashes($_POST['OtherInformation'])); $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } $Body .= "Name: "; $Body .= $Name; $Body .= "n"; $Body .= "Filename: "; $Body .= $Filename; $Body .= "n"; $Body .= "OtherInformation: "; $Body .= $OtherInformation; $Body .= "n"; $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> You could also do: <?php $EmailFrom = "[email protected]"; $EmailTo = "[email protected]"; $Subject = "FORM"; $Name = Trim(stripslashes($_POST['Name'])); $Filename = Trim(stripslashes($_POST['Filename'])); $OtherInformation = Trim(stripslashes($_POST['OtherInformation'])); $validationOK=true; if (!$validationOK) { print '<meta http-equiv="refresh" content="0;URL=error.htm">'; exit; } $Body .= "Name: "; $Body .= $Name; $Body .= "n"; $Body .= "Filename: "; $Body .= $Filename; $Body .= "n"; $Body .= "OtherInformation: "; $Body .= $OtherInformation; $Body .= "n"; $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); if ($success){ print '<meta http-equiv="refresh" content="0;URL=ok.htm">'; } else{ print '<meta http-equiv="refresh" content="0;URL=error.htm">'; } ?>
-
[SOLVED] IMPORTANT --- ERROR MESSAGE MAKING ME FEEL STUPID
Philip replied to kaimason1's topic in PHP Coding Help
The column 'Book' does not exist in your table, TEST1_contacts, on this line: $query="SELECT * FROM TEST1_contacts WHERE 'Book' LIKE '%$search%'"; -
include('usernamepassworddatabase.php'); You need quotes - and make sure that is the correct path to the file
-
$result = mysql_query($query) or die(mysql_error()); // run query $array = array(); // setup array while($row = mysql_fetch_assoc($result)) { $array[] = $row['col1'].' '.$row['col2']; // set whatever variables you are calling, you can also output here while you are at it } $storeInFile = implode('"\n", $array); // implode array to a single string fwrite($fp,$storeInFile); // write to file Something like that? edit: missing a variable, oops
-
I'm voting on the second one, with the guy facing you. As said, it's more personal as if he's inviting you in to watch the video. I think the flag should be a bit brighter though, but not overwhelming.