Jump to content

Mikedean

Members
  • Posts

    79
  • Joined

  • Last visited

    Never

Everything posted by Mikedean

  1. You'll have to reset the pointer in your results after your first while loop. mysql_data_seek( $result );
  2. Cool, change it to: $currentArrayPos = ( isset( $queryResults[$fieldName] ) ? count( $queryResults[$fieldName] ) : 0 );
  3. I turned it in to a function so you're able to use it somewhere else a lot easier. function returnResultsInColumns( $mysqlResult ) { $queryResults = NULL; if( mysql_num_rows($mysqlResult) > 0 ) { while($resultRow = mysql_fetch_array($mysqlResult)) { for ($intPos = 0; $intPos < mysql_num_fields($mysqlResult); $intPos++) { $fieldName = mysql_field_name($mysqlResult, $intPos); $currentArrayPos = count( $queryResults[$fieldName] ); $queryResults[$fieldName][$currentArrayPos] = $resultRow[$fieldName]; } } $htmlTable = "<table>"; foreach( $queryResults as $field => $results ) { $htmlTable.= "<tr>"; $htmlTable.= "<td>" . $field . "</td><td>" . implode( ", ", $results ) . "</td>"; $htmlTable.= "</tr>"; } $htmlTable.= "</table>"; return $htmlTable; } else { return "The query returned no results."; } } // Pass the result of the MySQL query into the function. $tableLayout = returnResultsInColumns( $result ); echo $tableLayout; It's untested but should work .
  4. Try removing the space that's before the .php. $modul = $_GET['m'] . '.php'; If that doesn't work, post the error you're getting.
  5. I'm guessing it's after someone has filled in a form (or something similar?) Perhaps setting a session variable after submitting the form, checking if it's set and then deleting it at the end of the script you want to stop refreshing in? Hope this helps!
  6. I guess, but it depends how fast it can grab the emails, you could see the page taking a while to load and so it would be much safer to just run a scheduled task. Although, you're right, you would be able to run the code whenever someone hits the page.
  7. <?php $array[0][0] = 1; $array[0][1] = 2; $array[0][2] = 3; $array[0][3] = 4; $array[0][4] = 5; $array[1][0] = 6; $array[1][1] = 7; $array[1][2] = 8; $array[1][3] = 9; $array[1][4] = 10; for( $i = 0; $i < count( $array ); $i++ ) { $randomNum = rand(0, 4); echo "Row ID: " . $array[$i][$randomNum] . " will have checked='1'<br />"; // Run SQL update. } ?> This will let you grab a random ID, but you would need to store the inserted ID's in an array.
  8. It depends on what you're actually trying to do, if you want a 'status' type system (e.g. Facebook, Twitter) then you could simply make a separate page which is mobile friendly which allows you to update that message. Or yes, you could write an email catching service but this would require a scheduled task to be run every X minutes to check for updates. If you could provide more details on what you actually intend to do that would be helpful.
  9. Yesideez, that won't make it random. You could store the ID's of the INSERTS in an array and use rand(0,5) to make it random and then UPDATE that row, however posting what you already have would be useful.
  10. As shlump says, put $_SESSION in capitals, but the following should (hopefully) resolve your problem. <?php session_start(); $nextCartKey = (isset( $_SESSION['cart'] ) ? count( $_SESSION['cart'] ) : 0); foreach ( $_POST as $key) $_SESSION['cart'][$nextCartKey] = $key; echo '<pre>'; print_r($_session); echo '</pre>'; ?> Hope this helps .
  11. I'm guessing it's $additionalHeaders = "From: My Web Site\r\n"; If you want it to display a name instead of the address then do. $additionalHeaders = "From: My Web Site <myemail@address.com>\r\n"; Hope this helps
  12. You'll need to learn the following mysql commands. mysql_connect(); mysql_select_db(); mysql_query(); mysql_fetch_assoc(); (there are multiple choices in for this command. E.g. mysql_fetch_row(), mysql_fetch_arrray() - They all do pretty much the same job though.) <?php $databaseConnection = mysql_connect( SERVER, USER, PASS ) or die( "Could not connect"); mysql_select_db( DATABASE, $databaseConnection ) or die( "Could not select the database" ); $queryResults = NULL; $theSQL= "SELECT * FROM <table>"; // * should never really be used, however as I do not know what columns you have I did it for simplicity. $theQuery = mysql_query( $theSQL, $databaseConnection ) or die( mysql_error() ); while( $resultRow = mysql_fetch_assoc( $theQuery ) ) { $queryResults[ count( $queryResults) ] = $resultRow; // place the contents of the row inside our results variable. Incrementing its key by 1. } var_dump( $queryResults ); ?> Read up on these commands and others at http://uk2.php.net/manual/en/book.mysql.php. Oops, and like Kevin said, use LIMIT in your query! Hope this helps!
  13. Your function is wrong anyway. It should read. function validate($post_value,$field_type,$required) { if(isset($post_value) && !empty(trim($post_value)) || !$required) { } else { } } This might in turn fix the problem so worth a try .
  14. I think you've misunderstood me so I'll try to explain better. In your current query to get the threads are you counting the amount of posts per thread? If yes, you then rename that virtual column and order by that. So essentially SELECT count( posts ) as threadPosts FROM forum ORDER BY threadPosts ASC is SELECT count( posts ) FROM forum ORDER BY count( posts ) ASC You don't need to have the column in the table, you just need to add a temporary one on the fly. If this still doesn't make any sense, please post your code for retrieving the post count and I'll take another look.
  15. You can order using a column you've defined in the query. E.g. SELECT count( posts ) as threadPosts FROM forum ORDER BY threadPosts ASC So just check whether they want to order it by posts (like you've already done) and then the order in which it needs to display. if(!isset($_GET['order'])) { $order = 'ID'; $ascension = 'DESC'; } else // No need for if else { $order = "threadPosts"; $ascension = 'ASC'; } $sql = "SELECT count( posts ) as threadPosts FROM forum ORDER BY $order $ascension";
  16. Just query the user name. $sql = mysql_query( "SELECT members FROM table WHERE members='" . $_POST["username"] . "'", $query ); if( mysql_num_rows( $sql ) > 0 ) echo "not"; That should do the job. I would also think about putting some SQL injection prevention in place.
  17. This is completely untested and I don't even think it would work, but. UPDATE tb1 SET (name=(SELECT name FROM tbl2 WHERE id=4), address=(SELECT address FROM tbl2 WHERE id=4), phone=(SELECT phone FROM tbl2 WHERE id=4), pin=(SELECT pin FROM tbl2 WHERE id=4), email=(SELECT email FROM tbl2 WHERE id=4)) WHERE id = 3 LIMIT 1 I'm not sure that it will work, but that's the only way I can think of it working using a query. Edit: Eek, or just follow the link Stephen posted
  18. //Output a line of the file until the end is reached if( file_exists( "example.txt" ) ) { $fileContents = file( "example.txt" ); $searchFor = "hello"; for( $i = 0; $i < count( $fileContents ); $i++ ) { if( strstr( $fileContents[$i], $searchFor ) ) unset( $fileContents[$i] ); } echo implode( "<br />", $fileContents ); } else { echo "File doesn't exist."; } You'll obviously have to save the file afterwards, but I thought for testing you're best to leave it out until you're happy.
  19. Firstly, when setting variables you need to use only 1 equal sign, 2 are used for conditional (if) statements. If you only want to change the value and not delete it, all you would need to do is: $_SESSION['language'] = "dutch"; If you do want to delete it. unset( $_SESSION['language'] );
  20. I could be completely wrong with what I assumed you was doing/trying to do, however this code works for me. <?php session_start(); if ($_POST['update']) { foreach ($_POST['qty'] as $k => $v) { // if the value is empty, 0 or negative // don't bother changing the cart if ($v != "" && $v >= 0) { $_SESSION['cart'][$k] = $v; } } } //this is the ADD to cart code, no problems if ($_POST['add']) { foreach ($_POST['qty'] as $k => $v) { // if the value is 0 or negative // don't bother changing the cart if ($v > 0) { //echo "V = $v and K = $k"; V = QTY and K = article $_SESSION['cart'][$k] = $_SESSION['cart'][$k] + $v; } } } if ($_POST['remove']) { for( $i = 0; $i < count( $_POST['qty'] ); $i++ ) { unset( $_SESSION['cart'][$_POST['qty'][$i]] ); } } ?> <form method="post"> <input type="text" name="qty[1]" /> <input type="submit" name="add" value="Add" /> </form> <form method="post"> <?php if( isset( $_SESSION['cart'] ) ) foreach( $_SESSION['cart'] as $k => $v ) echo "<input type='text' name='qty[" . $k . "]' value='" . $v . "' />"; ?> <input type="submit" name="update" value="Update" /> </form> <form method="post"> <?php if( isset( $_SESSION['cart'] ) ) foreach( $_SESSION['cart'] as $k => $v ) echo "<input type='checkbox' name='qty' value='" . $k . "' />"; ?> <input type="submit" name="remove" value="Remove" /> </form>
  21. This should work. <?php $date1 = strtotime( "now" ); $date2 = strtotime( "2010-02-20 22:58:00" ); $dateDiff = $date2 - $date1; $daysRemaining = floor($dateDiff/(60*60*24)); echo $daysRemaining . " day(s)"; ?>
  22. http://uk.php.net/function.array-count-values That should do it
  23. Sorry if I've misunderstood what you want to do, but this should do the trick. $theArray[0] = "Cocktail"; $theArray[1] = "Cocktail1"; $theArray[2] = "Cocktail2"; foreach( $theArray as $arrayKey => $arrayValue ) echo $arrayValue." <a href=$url&function=remove_favorite&cocktail=" . $arrayValue . "&ai=" . $arrayKey . ">[x]</a><br />";
  24. I'm sure you could do it in RegEx, but this is a way you can do it in PHP. <?php $string = "A*B*C COMPANY"; function strToProper( $theString ) { $differentWords = explode( " ", $theString ); for( $i = 0; $i < count( $differentWords ); $i++ ) { $thisWord = strtolower( $differentWords[$i] ); $thisWord = strtoupper( $thisWord[0] ) . substr( $thisWord, 1 ); $innerCapitals = explode( "*", $thisWord ); if( count( $innerCapitals != 0 ) ) { for( $n = 1; $n < count( $innerCapitals ); $n++ ) { $innerCapitals[$n] = strtoupper( $innerCapitals[$n][0] ) . substr( $innerCapitals[$n], 1 ); } $thisWord = implode( "", $innerCapitals ); } $differentWords[$i] = $thisWord; } return implode( " ", $differentWords ); } echo strToProper( $string ); ?>
  25. <?php $weekStart = strtotime( "-1 Sunday 00:00" ); $weekEnd = strtotime( "+1 Saturday 23:59" ); $todayStart = strtotime( "00:00" ); $todayEnd = strtotime( "23:59" ); echo date( "d/m/y H:i", $weekStart ) . "<br />"; echo date( "d/m/y H:i", $weekEnd ) . "<br />"; echo date( "d/m/y H:i", $todayStart ) . "<br />"; echo date( "d/m/y H:i", $todayEnd ) . "<br />"; ?> That should do the trick.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.