Jump to content

adam_bray

Members
  • Posts

    101
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by adam_bray

  1. Is there a function to get the active page id? You can adapt the array method to this - <?php $devices = array( 'android' => array( 'name' => 'Android app', '1' => 'http://androidlink.com/1', '2' => 'http://androidlink.com/2', ), 'ios' => array( 'name' => 'iPhone app', '1' => 'http://iphonelink.com/1', '2' => 'http://iphonelink.com/2', ), ); $page = (is_page( 1 )) ? 1 : 2; // Replace this with function to get active page print $devices[$os]['name'] . ': ' . $devices[$os][$page]; ?>
  2. Try using arrays - $devices = array( 'android' => array( 'name' => 'Android app', 'link' => 'http://androidlink.com/1', ), 'ios' => array( 'name' => 'iPhone app', 'link' => 'http://iphonelink.com/1', ), ); print $devices[$os]['name'] . ': ' . $devices[$os]['link'];
  3. Could be something to do with the session or cookies. Go through the code and put die('1'); to see how far you're getting before it messes up.
  4. That sounds like a CSS issue rather than PHP. Look up about CSS positioning of elements, that should help you out.
  5. I take it all you're asking is how to run a mysql query in php? http://uk1.php.net/mysqli_query
  6. Instead of animating the height which is fluid, why not animate the max-height? Start off and set the max height to 0, then change it to 1000px so it can expand depending on the content. If you get stuck then I've done a tutorial on this - http://www.adam-bray.com/blog/92/Animated+CSS+Accordion/
  7. This does what you need and stores the color information in 1 place. <?php // Store available colors $colors = array( 'black' => '#000000', 'blue' => '#0000ff', 'green' => '#00ff00', 'red' => '#ff0000', 'white' => '#ffffff', ); // If the form has been submit if( $_POST['color'] ) { die( 'You selected a ' . array_search( $_POST['color'], $colors ) . ' frame, that\'s ' . $_POST['color'] . ' in HEX!' ); } // Set up the form options $select_options = ''; foreach( $colors as $color => $hex ) { $select_options .= '<option value="'.$hex.'">'.$color.' Frame</option>' . "\n"; } ?> <form method="post" action="<?=$_SERVER['PHP_SELF'];?>"> <select name="color"> <option selected="true" disabled="true">Please select frame color</option> <?=$select_options;?> </select> </form>
  8. It's showing all the results because you haven't used a WHERE clause in your query. SELECT userinfo.name as name, userinfo.address as address, userlogin.username as username FROM userinfo INNER JOIN userlogin ON userlogin.user_id = userinfo.user_id WHERE userlogin.user_id = {$user_id}; You may want to check that $user_id is a number and clean it before putting it in the SQL like that though.
  9. You can do that using arrays - <?php $color_to_hex = array( 'black' => '#000000', 'blue' => '#0000ff', 'green' => '#00ff00', 'red' => '#ff0000', 'white' => '#ffffff', ); print $color_to_hex[$_POST['color']]; ?> $_POST['color'] would be one of the left values (a key) and it would print the right value (array value).
  10. This part of your query looks wrong - ON userinfo.user_id=userlogin=user_id Try - INNER JOIN userlogin ON userlogin.user_id = userinfo.user_id Question: Why do you have two user tables?
  11. What error do you get? If you use this, what happens? - $result = mysql_query($query) or die( mysql_error() );
  12. Count done using a left join - <?php $query = mysql_query( ' SELECT categories.category , COALESCE(cat_products.totalProducts,0) AS `totalProds` FROM categories LEFT OUTER JOIN ( SELECT prodCat , COUNT(*) AS totalProducts FROM product GROUP BY prodCat ) AS cat_products ON cat_products.prodCat = categories.category ORDER BY categories.category ASC;' ) or die( 'Query Error on line ' . __LINE__ . '<br />' . mysql_error() ); if( mysql_num_rows( $query ) > 0 ) { $return_string = ''; while( $cats = mysql_fetch_array( $query ) ) { $return_string .= '<li>'.$cats['category'].' (<strong>'.$cats['totalProds'].'</strong>)</li>'; } print $return_string; } else { print '<h3>There are no categories to display!</h3>'; } ?>
  13. That method is very insecure. Try this - <?php mysql_connect($theserver,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); if( preg_match( "/[0-9]/", $_GET['id'] ) ) { $question_query = mysql_query( "SELECT column1, column2 FROM questions WHERE id = '$_GET[id]';" ) or die( 'MySQL Error: ' . mysql_error() ); $num1 = mysql_num_rows($question_query); while( $row = mysql_fetch_object( $question_query ) ) { echo $row->column1 . '<br />'; echo $row->column2 . '<br />'; } } else { die( 'Invalid ID' ); } mysql_close(); ?>
  14. This should give you the answer - http://www.w3schools.com/tags/tag_audio.asp
  15. The method for doing that is the one already posted. The best way would be either convert that color to rgba or type it in normally, without the need for PHP.
  16. That's some funky CSS right there. You've set every line to !important which defeats the point. Yes there's a way to do what you want. Yes it's simple enough to see the lines you need to change.. but god knows where you're getting your colors from and how they're coming across. These are the 2 lines you need to change : background-color: <?= $cat_background_container_color ?> !important; opacity: <?= (empty($cat_background_container_opacity) || $cat_background_container_opacity == "0")?'1':$cat_background_container_opacity/100 ?> !important; I'm guessing the colors are HEX values, i.e. #FF0000 being red. To do what you want you need to use RGBA values - red, green, blue, alpha. Alpha being the opacity of that color. What that would give you is something along the lines of this - background-color: rgba( 255, 255, 255, .1 ); Or with your funky CSS/PHP hybrid - background-color: rgba(<?= $cat_background_container_color ?>,<?= (empty($cat_background_container_opacity) || $cat_background_container_opacity == "0")?'1':$cat_background_container_opacity/100 ?>); But remember: The above code won't work if your color ($cat_background_container_color) is a HEX value. If that doesn't work then that'll be the issue.
  17. Paypal IPN - https://developer.paypal.com/docs/classic/ipn/gs_IPN/
  18. if (mysqli_connect_errno()) $query = mysql_query(...) $result = mysqli_query(...) Are you using mysql or mysqli? The error is probably caused because you've used mysql when you've connected via mysqli.
  19. If you move the delete query above the select query then it will work as expected.
  20. I know this is now solved but ... for better error reporting you should do something like this - $result = mysql_query($query,$conn) or die( '<h1>You are doomed!</h1><p>'.mysql_error().'</p>' ); Then you'll actually know what's going wrong instead of seeing your generic error message.
  21. This should do what you need - $points = ( is_numeric($_POST['points']) && $_POST['points'] > 0 ) ? $_POST['points'] : 0; $columns[] = "points = " . $points; As said above, NULLIF() is a SQL function, you've tried to use it in PHP so the error tells you it doesn't exist.
  22. The simple option is to store your $_POST data in $_SESSION's. Here's a basic example on one page - <?php session_start(); if( $_POST['submit'] ) { if( strlen( $_POST['input'] ) < 10 ) { $_SESSION['data_input'] = $_POST['input']; } else { print 'Correct sized input!'; } } ?> <form method="post" action="<?=$_SERVER['PHP_SELF'];?>"> <input type="text" name="input" placeholder="Input" value="<?=$_SESSION['data_input'];?>" /> <input name="submit" type="submit" value="Submit Form" /> </form>
  23. It's hard to help without understanding how the array is structured. Here's my shot - <?php define( 'NUMCOLS', 4 ); foreach( $this->level as $level => $courses) { $count = 0; $total_courses = count( $courses ); ?> <div class="group" id="level<?=$level;?>"> <div class="controls"><button class="prev">Previous</button><button class="next">Next</button></div> <div class="pics" data-fx="scrollLeft" data-speed="300"> <?php foreach( $courses as $course => $records ) { foreach( $records as $record ) { if( $count <= $total_courses ) { echo '<div class="slide">'; # new row } echo $count; if( $count <= $total_courses ) { echo '</div>'; # new row } $count++; } } ?> </div> </div> <?php } #END FOREACH ?> I hope that helps. p.s. you don't need to open and close PHP tags on every line
×
×
  • 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.