Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. Well what does happen? Does the file have a .php extension?
  2. There is absolutely no PHP code in what you have posted.
  3. Instead of overwriting $menuDisplay every loop append to it: $menuDisplay .= '<a href="phpcustom.php?pid=' . $pid . '">' . $linklabel . '</a><br/>'; Then after the loop echo it.
  4. What do you mean "not working"? What do you expect it to do? All you're doing is overwriting $menuDisplay every loop.
  5. PHP, being a server-side language, has nothing to do with what happens after the page loads. PHP just does whatever you tell it to do, sends the output to the browser and then has nothing to do with it afterwards. This is why to get the effect you're looking for you need to use JavaScript, a client-side language. The JavaScript is fairly straightforward, it just submits the form that the select element belongs to. In order to have to option remain selected you will have to loop over all the options and determine which one was selected. For that option you define the attribute selected (selected="selected"). Something like this: <form method='post' action =""> <select name='add' onchange="this.form.submit();"> <?php $options = array('option 1', 'option 2'); foreach($options as $option) { echo '<option value="' . $option . '"'; if(isset($_POST['add']) && $_POST['add'] == $option) { echo ' selected="selected"'; } echo ">$option</option>\n"; } ?> </select> </form>
  6. onchange="this.form.submit();"
  7. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=305968.0
  8. Here's a tutorial on how to do that: http://bavotasan.com/tutorials/creating-a-jquery-mouseover-fade-effect/
  9. The problem when running it as a cron might be the paths; try making them absolute.
  10. You don't need 200 tables, and you don't need to create rows beforehand either. My previous example shows how you could fetch the data from the database. It made the assumption that the user wouldn't be able to pick their location though, it would just list the users' boxes in the order they appear in the database, but that wouldn't be too hard to change. Do you want a user to be able to select any where they want their box to be out of the 400,000 boxes?
  11. You can't mix and match mysql and mysqli functions. You'll need to use mysqli_real_escape_string.
  12. In the future when you're posting code please paste it in between [ code ][ /code ] tags (without the spaces). I've edited your post to put them in for you this time. To solve your problem remove all the whitespace before your call to header that is outside of the PHP tags (<?php ?>). This includes the whitespace in your include files.
  13. Oh, alright. Then you wouldn't want to be doing what I suggested in my previous post. Instead your code might look something like this: $im = imagecreatetruecolor(1000, 1000); $result = mysql_query("SELECT color FROM users"); // select information from the database $i = 0; while($row = mysql_fetch_assoc($result)) { $grid_column = $i % 200; $grid_row = floor($i / 200); imagefilledrect( $im, $grid_column * 5, $grid_row * 5, $grid_column * 5 + 5, $grid_row * 5 + 5, imagecolorallocate( $im, base_convert(substr($row['color'], 0, 2), 16, 10), // assuming the color column stores a hex value that looks like this: ffff99 base_convert(substr($row['color'], 2, 2), 16, 10), base_convert(substr($row['color'], 4, 2), 16, 10) ) ); ++$i; } header('Content-type: image/png'); imagepng($im); You can also use imagecolortransparent to make the rest of the image transparent. After that you'll need to use JavaScript to get the second half working, and perhaps some AJAX.
  14. When posting code please use code tags. Your code should look something like this: @mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql"); @mysql_select_db("$db_name") or die ("No Database"); 1. You need to remove the database name from the 4th parameter of mysql_connect and 2. The variable that holds your database name that you want to pass to mysql_select_db is $db_name not $communityDB.
  15. Make sure you have no whitespace on the page before <?php.
  16. Well exactly how are you intending on this working? Will you have a bunch of hex codes in the database and have them repeat over and over again in the image? If so then you can do something like this to have the colors repeat instead of being randomly selected: // assume this array came from the database $colors = array( 'ffff99', 'cfeef6', 'b2ebc5', 'ffffff', 'd7ebff', 'dfceb9', 'b3ccc5' ); // convert hex to RBG values foreach($colors as &$color) { $color = array( base_convert(substr($color, 0, 2), 16, 10), base_convert(substr($color, 2, 2), 16, 10), base_convert(substr($color, 4, 2), 16, 10) ); } $numColors = sizeof($colors); $im = imagecreatetruecolor(1000, 1000); for($i = 0;$i <= 200;++$i) { for($j = 0;$j <= 200;++$j) { //list($r, $g, $b) = $colors[array_rand($colors)]; list($r, $g, $b) = $colors[($i * 200 + $j) % $numColors]; imagefilledrectangle($im, $i * 5, $j * 5, $i * 5 + 5, $j * 5 + 5, imagecolorallocate($im, $r, $g, $b)); } } ... The only real difference is this line: list($r, $g, $b) = $colors[($i * 200 + $j) % $numColors]; Which instead of randomly selecting a color from the array, picks the next color in order starting with the first color in the array and repeating once it gets to the end.
  17. You could use array_unshift to prepend a useless item to the front of the array. I wouldn't recommend it though. The reason 0 was chosen for the start of array indexes is because it's typically more useful and less confusing.
  18. Don't use quotes because then it thinks that you're trying to insert the string "NULL": $sql="UPDATE product SET inactive=NULL WHERE id = '$item_id'";
  19. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=305902.0
  20. And here's an example that basically implements what PFMaBiSmAd just described. Again, as PFMaBiSmAd mentioned you would need to use the <img..> tag to reference this file. <?php $colors = array( 'ffff99', 'cfeef6', 'b2ebc5', 'ffffff', 'd7ebff', 'dfceb9', 'b3ccc5' ); // convert hex to RBG values foreach($colors as &$color) { $color = array( base_convert(substr($color, 0, 2), 16, 10), base_convert(substr($color, 2, 2), 16, 10), base_convert(substr($color, 4, 2), 16, 10) ); } $im = imagecreatetruecolor(1000, 1000); for($i = 0;$i <= 200;++$i) { for($j = 0;$j <= 200;++$j) { list($r, $g, $b) = $colors[array_rand($colors)]; imagefilledrectangle($im, $i * 5, $j * 5, $i * 5 + 5, $j * 5 + 5, imagecolorallocate($im, $r, $g, $b)); } } header('Content-type: image/png'); imagepng($im); ?> It's a pretty short example and fairly self explanatory if you check the manual for the corresponding functions. If you have any questions on how it works feel free to ask. It outputs a file that is about 68KB, so that's a fairly good size difference, a lot better than 1.7MB of HTML
  21. Just change this line: $avg = array_sum($review) / count($review); to: $avg = round(array_sum($review) / count($review), 2);
  22. We need more information to help you. What's the error message?
  23. Alex

    MOVED: PHP Problem

    This topic has been moved to PHP Coding Help. http://www.phpfreaks.com/forums/index.php?topic=305890.0
  24. It would probably be a better idea to use an array like in ToonMariner's solution, but if you really want to use variable variables you can do it like this: require_once("../Person/Person.php"); $count = $_POST['count']; $add = 0; while ($add < $count) { ${'var' . $add} = new Person('laryy'); $add++; }
×
×
  • 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.