jonsjava Posted April 24, 2008 Share Posted April 24, 2008 Hey all. I can't post the script I'm working on, but I need help with it. If you're willing and able, and you're a regular, send me a private message. I hate being so cloak-and-dagger, but it's a script for the company I work for. All I can say is this: it generates an image dynamically, based on what it finds in a file (variables). That way, they can link to the php file for an image reference. If you're interested in helping, please send me a private message. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2008 Author Share Posted April 24, 2008 Ok, after thinking about it, I can at least tell you what I need, and hope to get a generic code. I have a semi-working version, but that's the problem. Here's what I have (with some data removed): <?php if ($_GET['mode'] == "slient"){ $extList['gif'] = 'image/gif'; $username = "not_showing_you"; $password = "get_real"; $host = "00_I_C_U_8_1_2"; $db = "cant_show"; $link = mysql_connect($host, $username, $password) or die("connection error"); mysql_select_db($db, $link); $sql = "select * from `table` where `table_row` not in ('some_data', 'some_data2', 'some_data3') and `table_row` not like '%this_data%' and `table_row` !='' and `table_row` like '%symbol%' and `table_row_2` like '%something%'"; $session_count = 0; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)){ $session_count++; } $sql = "select * from `table` where `table_row` not in ('some_data') and `table_row` not like '%this_data%' and `table_row` !='' and `table_row` like '%something%' and pref_name like '%something%';"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)){ $session_count++; } include("stats2.php"); if ($count != $session_count){ $selected = "bad"; $file = "stats2.php"; $content = "<?php\n\$count = '{$session_count}'\n\$status='bad';\n?>"; $fh = fopen($file, "w+"); fwrite($fh, $content); fclose($fh); } else{ $selected = "good"; $file = "stats2.php"; $content = "<?php\n\$count = '{$session_count}'\n\$status='good';\n?>"; $fh = fopen($file, "w+"); fwrite($fh, $content); fclose($fh); } include($selected.".gif"); } if($_GET["image"] == "good"){ include("good.gif"); } if($_GET["image"] == "bad"){ include("bad.gif"); } Quote Link to comment Share on other sites More sharing options...
SharkBait Posted April 24, 2008 Share Posted April 24, 2008 Not sure why you use a counter while you're going through the first while() loop for your query. You can just use $session_count = mysql_num_rows(); and that will tell you how many rows it retrieved from your query. And I don't see any dynamically generated images in the script either. I need coffee i think! Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2008 Author Share Posted April 24, 2008 the $count will auto-increment the 2nd array. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2008 Author Share Posted April 24, 2008 .........and that's where I need to check to see if I gave you everything. sorry. Quote Link to comment Share on other sites More sharing options...
soycharliente Posted April 24, 2008 Share Posted April 24, 2008 Maybe it's your ATTEMPT at new lines here: $content = "<?phpn$count = '{$session_count}'n$status='good';n?>"; No slashes at all? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2008 Author Share Posted April 24, 2008 nope, it writes the file fine. I've escaped everything properly there. The issue is if I attempt in silent mode, it displays nothing. Let me restate what it's supposed to do (I didn't state it well before). Based on the results, if they don't add up to be the same as the previous result, it is supposed to output "bad.gif", and if it's the same as the previous result, it outputs "good.gif". If you aren't going by the "silent mode", you should be calling it like so: ?image=good or ?image=bad <- those work fine. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2008 Author Share Posted April 24, 2008 Maybe it's your ATTEMPT at new lines here: $content = "<?phpn$count = '{$session_count}'n$status='good';n?>"; No slashes at all? oh, and this forum has removed my slashes. sorry about that too. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted April 24, 2008 Share Posted April 24, 2008 I don't see where $count is first set (i'm working with your code in notepad++ if($count1 == $count2) { // use good.gif } else { // user bad.gif } You can't use include('image.gif') as that includes the code for the page. You would need to do something like echo "<img src=\"{$selected}.gif\" />"; To display it to the screen. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted April 24, 2008 Share Posted April 24, 2008 Wait, your trying to include() an image? And they did make an edit button for a reason you know. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2008 Author Share Posted April 24, 2008 I don't see where $count is first set (i'm working with your code in notepad++ if($count1 == $count2) { // use good.gif } else { // user bad.gif } You can't use include('image.gif') as that includes the code for the page. You would need to do something like echo "<img src=\"{$selected}.gif\" />"; To display it to the screen. I include the images, because when they pull the image, they do "<img src="image.php">"(the name of the file), which in turn calls the proper image in an include. that part works. it's the auto checking feature of ?mode=silent that's causing the issue. if we manually call it (image.php?image=good) it works fine. $count is in the included file that is overwritten each check (stats2.php) Quote Link to comment Share on other sites More sharing options...
SharkBait Posted April 24, 2008 Share Posted April 24, 2008 Ok after looking over your code this is what I came up with. Shortened it a bit to clean up bits that were a bit repetitive. If it is wrong then.. your logic in the code is wrong <?php if (isset($_GET['mode']) && $_GET['mode'] == "slient"){ $extList['gif'] = 'image/gif'; $username = "not_showing_you"; $password = "get_real"; $host = "00_I_C_U_8_1_2"; $db = "cant_show"; $link = mysql_connect($host, $username, $password) or die("connection error"); mysql_select_db($db, $link); $sql = "select * from `table` where `table_row` not in ('some_data', 'some_data2', 'some_data3') and `table_row` not like '%this_data%' and `table_row` !='' and `table_row` like '%symbol%' and `table_row_2` like '%something%'"; $session_count = 0; $result = mysql_query($sql); // Get number of results $session_count = mysql_num_rows(); $sql = "select * from `table` where `table_row` not in ('some_data') and `table_row` not like '%this_data%' and `table_row` !='' and `table_row` like '%something%' and pref_name like '%something%';"; $result = mysql_query($sql); // get number of results and add to previous total $session_count += mysql_num_rows(); $file = "stats2.php"; include($file); if ($count != $session_count){ $selected = "bad"; $content = "<?php\n\$count = '{$session_count}'\n\$status='bad';\n?>"; } else { $selected = "good"; $content = "<?php\n\$count = '{$session_count}'\n\$status='good';\n?>"; } $fh = fopen($file, "w+"); fwrite($fh, $content); fclose($fh); include($selected.".gif"); } if($_GET["image"] == "good"){ include("good.gif"); } if($_GET["image"] == "bad"){ include("bad.gif"); } ?> Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2008 Author Share Posted April 24, 2008 getting desparate... here's the complete code (tables and all. only slightly modified) <?php if (isset($_GET['mode']) && $_GET['mode'] == "slient"){ $extList['gif'] = 'image/gif'; $username = "<hidden>"; $password = "<hidden>"; $host = "<hidden>"; $db = "horde"; $link = mysql_connect($host, $username, $password) or die("connection error"); mysql_select_db($db, $link); $sql = "select * from horde_prefs where pref_value not in ('<hidden>', '<hidden>', '<hidden>') and pref_value not like '%@my_company%' and pref_value !='' and pref_value like '%@%' and pref_name like '%reply%'"; $result = mysql_query($sql); // Get number of results $session_count = mysql_num_rows(); $sql = "select * from `table` where `table_row` not in ('some_data') and `table_row` not like '%this_data%' and `table_row` !='' and `table_row` like '%something%' and pref_name like '%something%';"; $result = mysql_query($sql); // get number of results and add to previous total $session_count += mysql_num_rows(); $file = "stats2.php"; include($file); if (isset($count)){ if ($count != $session_count){ $selected = "bad"; $content = "<?php\n\$count = '{$session_count}'\n\$status='bad';\n?>"; } else { $selected = "good"; $content = "<?php\n$count = '{$session_count}'\n\$status='good';\n?>"; } $fh = fopen($file, "w+"); fwrite($fh, $content); fclose($fh); include($selected.".gif"); } else{ $content = "<?php\n$count = '{$session_count}'\n\$status='good';\n?>"; $fh = fopen($file, "w+"); fwrite($fh, $content); fclose($fh); include("good.gif"); } } if($_GET["image"] == "good"){ include("good.gif"); } if($_GET["image"] == "bad"){ include("bad.gif"); } ?> when I run the code: [root@mail4 test]# php image.php -e PHP Notice: Undefined index: image in /var/www/ssl/test/image.php on line 41 PHP Notice: Undefined index: image in /var/www/ssl/test/image.php on line 44 [root@mail4 test]# I run the code after adding this line to the top: <?php $_GET['mode'] = "silent"; forgot to mention: it outputs nothing, and now no longer writes stats2.php Quote Link to comment Share on other sites More sharing options...
haku Posted April 24, 2008 Share Posted April 24, 2008 I'm sorry, as I am replying without looking too closely at your whole code, but I can see a couple quick problems that may point you in the right direction: 1) Your errors are the result of using $_GET["image"], but you must not have 'image' in your URL. You should have something that looks like www.something.com/page.php?image=someimage. Without the image=____, the variable doesn't exist, and you get that error. 2) You cannot include an image into your script. Images don't work that way. If you want to display an image at that point, then echo an image tag, with the path to the image you want to display. For example, instead of this: include("good.gif"); Use this: echo "<img src=\"good.gif\" alt=\"yossha\" />"; (note: 'yossha' can be anything you want) Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2008 Author Share Posted April 24, 2008 you can include them, and it works, so long as that's the last thing you do, and you don't output anything first. Then you can simply do an <image source="image.php">. that part is working fine. it's the silent mode that's killing me. but you did give me an idea... (checking it out now) Quote Link to comment Share on other sites More sharing options...
haku Posted April 24, 2008 Share Posted April 24, 2008 Including the image would only include it into your file, it doesn't output it to the browser. You need to have the image tags, which as far as I can see, you don't. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2008 Author Share Posted April 24, 2008 here's it in action: (moved to another server) as you can see, including the image works just fine. Now that you see the issue isn't with the include, any ideas? it's just when I request it via mode=silent oh, and where you're seeing the images, mode=silent won't work (the db the query goes through doesn't exist on this server) Quote Link to comment Share on other sites More sharing options...
haku Posted April 24, 2008 Share Posted April 24, 2008 Honestly, I still don't know what the overall problem is, but I can tell you that this is a problem: $_GET['mode'] = "silent"; $_GET variables are set in the URL. They cannot be set in your script. So maybe this is causing an error for you. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2008 Author Share Posted April 24, 2008 fixed it. working code: <?php if (isset($_GET['image'])){ if($_GET['image'] == "good"){ $selected = "good"; } if($_GET['image'] == "bad"){ $selected = "bad"; } } else{ $selected = "nothing"; $count = 0; $extList['gif'] = 'image/gif'; $username = "<hidden>"; $password = "<hidden>"; $host = "<hidden>"; $db = "<hidden>"; $link = mysql_connect($host, $username, $password) or die("connection error"); mysql_select_db($db, $link); $sql = "select * from horde_prefs where pref_value not in ('<hidden>', '<hidden>', '<hidden>') and pref_value not like '%@my_company%' and pref_value !='' and pref_value like '%@%' and pref_name like '%reply%'"; $result = mysql_query($sql); // Get number of results $session_count = mysql_num_rows(); $sql = "select * from `table` where `table_row` not in ('some_data') and `table_row` not like '%this_data%' and `table_row` !='' and `table_row` like '%something%' and pref_name like '%something%';"; $result = mysql_query($sql); $session_count += mysql_num_fields($sql); $file = "stats2.php"; include($file); if (isset($count)){ if ($count != $session_count){ $selected = "bad"; $content = "<?php\n\$count = '{$session_count}';\n\$status='bad';\n?>"; } else { $selected = "good"; $content = "<?php\n\$count = '{$session_count}';\n\$status='good';\n?>"; } $fh = fopen($file, "w+"); fwrite($fh, $content); fclose($fh); include($selected.".gif"); } else{ $content = "<?php\n\$count = '{$session_count}';\n\$status='good';\n?>"; $fh = fopen($file, "w+"); fwrite($fh, $content); fclose($fh); $selected = "good"; } } /*include($selected.".gif");*/ include($selected.".gif"); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.