Including script in random image

Post January 10th, 2005, 2:21 pm

I have the following script.

PHP Code: [ Download ] [ Select ]
 
<? header(“Content-type: image/jpeg”);
 
$im = imagecreate(50,100);
 
$bg = imagecolorallocate($im,255,255,255);
 
$fg = imagecolorallocate($im,100,120,130);
 
$borc = imagecolorallocate($im,0,0,0); imagefill($im,0,0,$bg);
 
imagerectangle($im,0,0,99,99,$borc);
 
imagestring($im,1,20,45,”Hello World”,$fg);
 
 imagejpeg($im); imagedestroy($im);
 
?>
  1.  
  2. <? header(“Content-type: image/jpeg”);
  3.  
  4. $im = imagecreate(50,100);
  5.  
  6. $bg = imagecolorallocate($im,255,255,255);
  7.  
  8. $fg = imagecolorallocate($im,100,120,130);
  9.  
  10. $borc = imagecolorallocate($im,0,0,0); imagefill($im,0,0,$bg);
  11.  
  12. imagerectangle($im,0,0,99,99,$borc);
  13.  
  14. imagestring($im,1,20,45,”Hello World”,$fg);
  15.  
  16.  imagejpeg($im); imagedestroy($im);
  17.  
  18. ?>


Now I have the following script to get information out of a database

PHP Code: [ Download ] [ Select ]
<?
 
include('inc/config.php'); ?>
 
 
 
<b>Last Song played, Author, and When Played</b>
 
 
 
<?
 
 
 
$result = mysql_query("SELECT * FROM `historylist` ");
 
 
 
echo "<table>";
 
while ($row=mysql_fetch_assoc($result)) {
 
 
 
$date_played=$row['date_played'];
 
$title=$row['title'];
 
$artist=$row['artist'];
 
 
 
echo "<tr><td>
 
$date_played - $name</td>
 
</tr>";
 
 
 
}
 
 
 
echo "<table>";
 
 
 
?>
  1. <?
  2.  
  3. include('inc/config.php'); ?>
  4.  
  5.  
  6.  
  7. <b>Last Song played, Author, and When Played</b>
  8.  
  9.  
  10.  
  11. <?
  12.  
  13.  
  14.  
  15. $result = mysql_query("SELECT * FROM `historylist` ");
  16.  
  17.  
  18.  
  19. echo "<table>";
  20.  
  21. while ($row=mysql_fetch_assoc($result)) {
  22.  
  23.  
  24.  
  25. $date_played=$row['date_played'];
  26.  
  27. $title=$row['title'];
  28.  
  29. $artist=$row['artist'];
  30.  
  31.  
  32.  
  33. echo "<tr><td>
  34.  
  35. $date_played - $name</td>
  36.  
  37. </tr>";
  38.  
  39.  
  40.  
  41. }
  42.  
  43.  
  44.  
  45. echo "<table>";
  46.  
  47.  
  48.  
  49. ?>


How would I combine the two scripts to make an image of what I last played?

Basically what I want the image to be is this

Quote:
|---------------------------------------------------|
|Song Last Played: <enter song last played> |
|---------------------------------------------------|


that is close enough



Also can you fix the first script. theres something wrong. and can you tell me or show me a link on how to retreve the last mysql field from a table?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post January 10th, 2005, 2:21 pm

Post January 10th, 2005, 6:02 pm

what happened to RichB's post.

well here is almost the final product

http://www.your4rums.zinix.net/song/song2.php
  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post January 10th, 2005, 7:17 pm

I was going to edit it to make it more clear and messed it up, so I deleted it and was called away from the computer before I could redo it. Anyway the advice was to keep the image script in a separate file and pass the title in the url of an img tag which I see you've done. I didn't think of it before, but you should encode the title before passing it in case characters like an ampersand occur in the title which could mess things up:

Code: [ Download ] [ Select ]
$title=$row['title'];
$title=urlencode($title);
  1. $title=$row['title'];
  2. $title=urlencode($title);
Free Programming Resources

Post January 10th, 2005, 7:21 pm

thanks now can you give me a hint on my next question.

Question:

Ok I have no idea how to do this so

How do I select the last field of a row.

It is on auto increasement if that helps. I will supply more info if needed
  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post January 10th, 2005, 7:49 pm

I'm not sure I understand. You can select any fields that you want in your query. Based upon your first post I'm wondering if you mean you want to select the just the last row in the table - the one with the highest autoincrement value..

In other words: you want to have only one image created with the most recent song played.
Free Programming Resources

Post January 11th, 2005, 5:29 am

correct. but thats what I ment
  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post January 11th, 2005, 10:28 am

Ok, then I think you want to do something like this:

PHP Code: [ Download ] [ Select ]
$result = mysql_query("SELECT * FROM `historylist` ORDER BY id desc LIMIT 0,1")


That should select only the record with the highest autoincrement field, which should be the last record entered. You may have to change id to match whatever you named your autoincrement field.
Free Programming Resources

Post January 11th, 2005, 11:46 am

PHP Code: [ Download ] [ Select ]
<?
 
include('inc/config.php');
 
$result = mysql_query("SELECT * FROM `historylist` ORDER BY ID desc LIMIT 0,1")
 
while ($row=mysql_fetch_assoc($result)) {
 
 
 
$title=$row['title'];
 
$title=urlencode($title);
 
 
 
echo "<tr><td>
 
<img src=\"image.php?title=$title\" width=\"300\" height=\"50\" alt=\"last played\">
 
</td>
 
</tr>";
 
 
 
}
 
 
 
echo "</table>";
 
 
 
?>
  1. <?
  2.  
  3. include('inc/config.php');
  4.  
  5. $result = mysql_query("SELECT * FROM `historylist` ORDER BY ID desc LIMIT 0,1")
  6.  
  7. while ($row=mysql_fetch_assoc($result)) {
  8.  
  9.  
  10.  
  11. $title=$row['title'];
  12.  
  13. $title=urlencode($title);
  14.  
  15.  
  16.  
  17. echo "<tr><td>
  18.  
  19. <img src=\"image.php?title=$title\" width=\"300\" height=\"50\" alt=\"last played\">
  20.  
  21. </td>
  22.  
  23. </tr>";
  24.  
  25.  
  26.  
  27. }
  28.  
  29.  
  30.  
  31. echo "</table>";
  32.  
  33.  
  34.  
  35. ?>


how come that code doesn't work. I get error on line 4 unexpected while
  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post January 11th, 2005, 11:51 am

I forgot to put a semicolon at the end of the example select line. Sorry about that. You don't really need the while loop for that since it will only loop once, but you do need to put the semicolon at the end of the line above.
Free Programming Resources

Post January 11th, 2005, 11:59 am

thanks, it now works. the only problem is how I get it to show in my sig
  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post January 11th, 2005, 12:48 pm

Er, I had no idea that's where you were going with it. I thought you were going to incorporate it into your own page. Let me look into it and see what I can come up with. The database code will have to go in with the image script after all, and php files generating images don't seem to work directly, but I think I know a way around that.
Free Programming Resources
  • darkermoon
  • Expert
  • Expert
  • User avatar
  • Joined: May 17, 2004
  • Posts: 543
  • Loc: Riverdale, MD
  • Status: Offline

Post January 11th, 2005, 1:14 pm

I made php parse .jpg files, lmao which, allowed me to have a sig that is actually php.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post January 11th, 2005, 2:06 pm

I found a tutorial on this, but I'm still having trouble getting the image to display. It keeps asking if I want to download instead of displaying the image.
Free Programming Resources

Post January 11th, 2005, 2:54 pm

the reason I wanated to post it in my sig is because I am currently running a part time radio station and I want show what is being played. Thanks for the help so far

Post January 11th, 2005, 2:57 pm

since I figured out what I am going to do which is follow those directions. can you help me change from what I currently have to include the image I make insted of making one please. Thanks for all the help

heres what I have

PHP Code: [ Download ] [ Select ]
<?php
 
// tell the user's browser that it is an image
 
header("Content-type: image/png");
 
 
 
// load the background
 
$image = imagecreatefrompng("blank.png");
 
 
 
// define the color black (the colour of the text)
 
$clr_black = imagecolorallocate($image, 0, 0, 0);
 
 
 
// Now let's add the text
 
// You are going to need to pull your own text from a database
 
// of your own.
 
$result = mysql_query("SELECT * FROM `historylist` ORDER BY ID desc LIMIT 0,1")
 
   
 
// draw heading
 
 
 
imagestring($image,"Last Played Song", $clr_black);
 
 
 
while ($row = mysql_fetch_array($result))
 
 
 
$title=$row['title'];
 
$title=urlencode($title);
 
 
 
{
 
 
 
    // draw the last 5 tutorial titles
 
    imagestring($image, $row['title'], $clr_black);
 
}
 
 
 
// and now... we display the image
 
imagepng($image);
 
imagedestroy($image);
 
?>
  1. <?php
  2.  
  3. // tell the user's browser that it is an image
  4.  
  5. header("Content-type: image/png");
  6.  
  7.  
  8.  
  9. // load the background
  10.  
  11. $image = imagecreatefrompng("blank.png");
  12.  
  13.  
  14.  
  15. // define the color black (the colour of the text)
  16.  
  17. $clr_black = imagecolorallocate($image, 0, 0, 0);
  18.  
  19.  
  20.  
  21. // Now let's add the text
  22.  
  23. // You are going to need to pull your own text from a database
  24.  
  25. // of your own.
  26.  
  27. $result = mysql_query("SELECT * FROM `historylist` ORDER BY ID desc LIMIT 0,1")
  28.  
  29.    
  30.  
  31. // draw heading
  32.  
  33.  
  34.  
  35. imagestring($image,"Last Played Song", $clr_black);
  36.  
  37.  
  38.  
  39. while ($row = mysql_fetch_array($result))
  40.  
  41.  
  42.  
  43. $title=$row['title'];
  44.  
  45. $title=urlencode($title);
  46.  
  47.  
  48.  
  49. {
  50.  
  51.  
  52.  
  53.     // draw the last 5 tutorial titles
  54.  
  55.     imagestring($image, $row['title'], $clr_black);
  56.  
  57. }
  58.  
  59.  
  60.  
  61. // and now... we display the image
  62.  
  63. imagepng($image);
  64.  
  65. imagedestroy($image);
  66.  
  67. ?>


that even close to correct
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post January 11th, 2005, 2:57 pm

Post Information

  • Total Posts in this topic: 26 posts
  • Users browsing this forum: No registered users and 111 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.