Philip
Staff Alumni-
Posts
4,665 -
Joined
-
Last visited
-
Days Won
20
Everything posted by Philip
-
Make sure you are using the correct path to the file - which you need to use the FULL path, not just a relative path. require "inc/init.php"; to: require "/home/bobnkile/public_html/inc/init.php";
-
How do I convert a query result into variables?
Philip replied to Skipjackrick's topic in PHP Coding Help
$results[0]['angler']; Would show '1' Also, I didn't think about it until now, but change this line: while($row = mysql_fetch_array($angler)) { to: while($row = mysql_fetch_assoc($angler)) { It'll change your array a bit: Array ( [0] => Array ( [angler] => 1 ... Basically, just the name key's instead of the numeric ones too -
How do I convert a query result into variables?
Philip replied to Skipjackrick's topic in PHP Coding Help
Okay, <?php $query = "SELECT angler, team_id FROM anglers WHERE team_id=1 GROUP BY angler LIMIT 4;" $angler = mysql_query($query) or die(mysql_error()); // run a loop, to get each row: while($row = mysql_fetch_array($angler)) { // I'd recommend using an array, I think it'd be easier: // now, this will create a multi-dimensional array. if you just want one value you can call it via row // and the column name in your DB (i.e. $row['id']) $results[] = $row; } echo '<pre>'; // just for formatting, open // show your variables: print_r($results); echo '</pre>'; //just for formatting, close ?> -
Just edited this in:
-
How do I convert a query result into variables?
Philip replied to Skipjackrick's topic in PHP Coding Help
Okay, what exactly are trying to do, I think I misunderstood? anglerA <- would be the value coming out of the DB, or just the variable holding the value? -
Dang, stupid parentheses. Thanks! That shouldn't make a difference though, the parenthesis are optional.
-
How do I convert a query result into variables?
Philip replied to Skipjackrick's topic in PHP Coding Help
If you're wanting to set the variable name, $tempVar = "myVar"; $$tempVar = "myValue"; echo $myVar; // prints "myValue" -
That's all done in Flash
-
cron job with variable in path eg. filename.php?string=1
Philip replied to APuppyDog's topic in PHP Coding Help
Use $argv in the PHP script, and when calling it. call it like a command line: php /path/to/file/filename.php -string=1 -
@gevans: Well, when I added the <?php ?> to the file its not displayed on the webpage. However, it still won't connect to MySQL. I changed the " .inc " extension to ".php" just to elminate any further questioning. My dbconnect file <?php // Database Variables $dbhost = "localhost"; $dbuser = "aaaaaa"; $dbpass = "aaaaaaaaaaaaa"; $dbname = "aaaaaaaa"; $MYSQL_ERRNO = ""; $MYSQL_ERROR = ""; // Connect To Database function db_connect() { global $dbhost, $dbuser, $dbpass, $dbname; global $MYSQL_ERRNO, $MYSQL_ERROR; $link_id = mysql_connect($dbhost, $dbuser, $dbpass); if(!$link_id) { $MYSQL_ERRNO = 0; $MYSQL_ERROR = "Connection failed to $dbhost."; return 0; } else if(!mysql_select_db($dbname)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); return 0; } else return $link_id; } // Handle Errors function sql_error() { global $MYSQL_ERRNO, $MYSQL_ERROR; if(empty($MYSQL_ERROR)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); } return "$MYSQL_ERRNO: $MYSQL_ERROR"; } // Print Error Message function error_message($msg) { printf("Error: %s", $msg); exit; } // Connection String Example # $link_id = db_connect($dbname); # if(!$link_id) error_message(sql_error()); # # $query = "SELECT * FROM test_table"; # $result = mysql_query($query); # # if(!$result) error_message(sql_error()); # # $data = mysql_fetch_array($result); ?> @OP: I'm looking at the page where you call the includes, where are you running your function 'db_connect()' ?
-
I'm not really getting what you're trying to do, but I'll give it a stab: $mainID = explode(', ', $a['mainID']); // main ID from earlier // now, let's see if id2 is in the array, if so select the option, if not ignore if(in_array($id2, $mainID)) $selected = 'selected'; else $selected = ''; // show the option echo '<option value="'.$id2.'" '.$selected.'>'.$name2.'</option>';
-
They must change their password upon first login.
-
Yup, there needs to be a ;... however, where is "mydatabase" coming from?
-
Here we go, $a = array('help4'=>'657', 'blue1' => '999'); $first = 'help'; $last = '4'; echo $a[$first.$last]; //echos 657
-
Get the length with strlen, if its longer than you want, chop it off with substr
-
PHP noob, need help with echo vs. return in functions
Philip replied to sigkill-9's topic in PHP Coding Help
<?php // I'll show you both ways: function process_form_echo() { echo "<b>Sender Details:</b><br />"; echo "<hr />"; echo " " . $_POST['sender_name']."<br />"; echo " " . $_POST['sender_address']."<br />"; echo " " . $_POST['sender_city'].", ".$_POST['sender_state']." ".$_POST['sender_zipcode']."<br />"; echo "<br /><br />"; echo "<b>Recipient Details:</b><br />"; echo "<hr />"; echo " " . $_POST['recipient_name']."<br />"; echo " " . $_POST['recipient_address']."<br />"; echo " " . $_POST['recipient_city'].", ".$_POST['recipient_state']." ".$_POST['recipient_zipcode']."<br />"; echo "<br /><br />"; echo "<b>Package Details:</b><br />"; echo "<hr />"; echo " Dimensions: " . $GLOBALS['pkgLength'] . "”L x " . $GLOBALS['pkgWidth'] . "”W x " . $GLOBALS['pkgHeight'] . "”H<br />"; echo " Weight: " . $GLOBALS['pkgWeight']." Lbs."; echo "<br /><br />"; } function process_form_return() { // note you could continue to the variable with: // $returnVar = "blah // blah blah blah"; // but I think it's cleaner coding the following way // also, be careful with globals. I know they teach that still, but just be careful. $returnVar = "<b>Sender Details:</b><br />"; $returnVar .= "<hr />"; $returnVar .= " " . $_POST['sender_name']."<br />"; $returnVar .= " " . $_POST['sender_address']."<br />"; $returnVar .= " " . $_POST['sender_city'].", ".$_POST['sender_state']." ".$_POST['sender_zipcode']."<br />"; $returnVar .= "<br /><br />"; $returnVar .= "<b>Recipient Details:</b><br />"; $returnVar .= "<hr />"; $returnVar .= " " . $_POST['recipient_name']."<br />"; $returnVar .= " " . $_POST['recipient_address']."<br />"; $returnVar .= " " . $_POST['recipient_city'].", ".$_POST['recipient_state']." ".$_POST['recipient_zipcode']."<br />"; $returnVar .= "<br /><br />"; $returnVar .= "<b>Package Details:</b><br />"; $returnVar .= "<hr />"; $returnVar .= " Dimensions: " . $GLOBALS['pkgLength'] . "”L x " . $GLOBALS['pkgWidth'] . "”W x " . $GLOBALS['pkgHeight'] . "”H<br />"; $returnVar .= " Weight: " . $GLOBALS['pkgWeight']." Lbs."; $returnVar .= "<br /><br />"; return $returnVar; } process_form_echo(); echo '<br />vs:<br />'; $newVar = process_form_return(); echo $newVar; ?> Basically, using a return will allow you to further manipulate /format the output before you output it. When just echoing the data, it goes straight to the output buffer, whereas with a return, the function 'returns' a variable. You can then do whatever you please to this variable. Another, maybe better example on why you'd want to do this: <?php function math_add_echo($num) { $num = $num + 2; echo $num; } function math_add_return($num) { $num = $num + 2; return $num; } // we'll call math_add_echo and cant do anything with the number: math_add_echo(4); // but lets say we want to add a few more the result of our function: $mathVar = math_add_return(4); $mathVar = $mathVar + 3; echo $mathVar; ?> -
SELECT * FROM `history` ORDER BY `id` DESC LIMIT 10
-
Take a look into ROUND(), it should be what you're looking for
-
It will not, you'd have to use $_FILES['fileField']['name']
-
You might want to read into a tutorial on how to upload files in PHP: http://www.tizag.com/phpT/fileupload.php
-
It's giving you an error, because you are trying to continue (concatenating) the variable (with use of .=) when the variable doesn't exist beforehand. Change: // prepare email body text $Body .= "\n"; to: // prepare email body text $Body = "\n";
-
Place you're code in here when posting That'll format it to: Place you're code in here It's just easier for us to read your code with the syntax highlighting, and we don't have to scroll down the page. As stated before, are you sure this is the search form code - not the actual form, but the code once you process it? In the code above, all I saw was $query_ToolResults = "SELECT * FROM tooltable"; with no WHERE clause
-
Honestly, this is what I would do: Have a script automatically guess the date, based on when the last meeting. This field should still be editable, so you can override it if needed. Next, have a list of your members with a checkbox if they attended or not - have them all defaulted as checked, and just take off the ones you don't want. Or, going with the same lines, instead of checkboxes, use an ajax 'auto complete' field and you could just type the names of the people who didn't show up (this would probably be the quicker way when filling out attendance logs - but more labor intensive to setup.) Then, submit the form post it to your DB and you're set.
-
How is your member table structured? Basic structure should be something like: userIDName 1Joe Then just create a new table (attendance), with userID and the meeting time/date. When a member is no longer, you could prune them to save space, but I wouldn't worry about it. OR, thinking about it, you could have one row per meeting - meeting time/date + imploded array of members (something like: 1,4,5,7,9...)