SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding category to simple news script..

    Woohoo, my first post, of what I hope is many
    OK, here goes. Im hoping somebody can help me out here.

    I'm building a simple news posting script using PHP and MySQL, and I'm close to completing it. The problem I'm having though, is adding images to the post.

    I have been able to include the text without any problem, but I would like to be able to include a picture next to the news post.

    I have a dir on my server which holds the pictures I would like to include and is linked via a table in my db. Now, the problem I'm having is being able to select one of these pictures to include in the post. I can display the pictures using simply echo commands, but then, how do I select a picture I would like to use?

    I've set up a simple script to show the records in the db if this is any help @ http://whitereview.co.uk/ups/contents2.php

    A great example of the kind of thing I want, is the avatar list on this forum. The images are displayed with the option of checking an avatar you would like to use. Same principle really...

    I've looked everywhere and read my books, but I can't find a solution anywhere. I'm stuck. Any ideas?
    Last edited by Ian M; Jul 1, 2002 at 15:45.

  2. #2
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You would somehow need to link the images with the posts. I would put another a field in the post table called IID for ImageID then it would match up with a related image that had the ID of IID.

  3. #3
    SitePoint Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I'm on to that way of thinking. OK, each image has a unique ID. If you look at the page I listed, each image has a record ID starting from 000001.

    So thats a start Now, if I can somehow, adjust contents.php so that each image listed has a radio button which can be checked, then maybe, I can send that checked image result back to the php news script and insert it by record ID.

    Sounds good in principle. Now, I just need to implement it Help...

  4. #4
    SitePoint Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm making progress, but its slow, and I'm not passing the variable value thru correctly...

    Here is what I have so far..

    PHP Code:
    <?
    $username
    ="username";
    $password="password";
    $database="database";

    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");
    $query="SELECT * FROM myfiles";
    $result=mysql_query($query);

    $num=mysql_numrows($result); 

    mysql_close();

    ?>

    <form>

    <?

    $i
    =0;
    while (
    $i $num) {

    $RecordID=mysql_result($result,$i,"RecordID");
    $username=mysql_result($result,$i,"username");
    $title=mysql_result($result,$i,"title");
    $file_location=mysql_result($result,$i,"file_location");
    $file=mysql_result($result,$i,"file");

    ?>

    <input type=radio name=id value=<? echo "$RecordID"?>> <img src="<? echo "$file_location$file"?>" height=50 width=50><br>

    <?
    ++$i;


    echo 
    "<input type=\"hidden\" name=\"action\" value=\"<? echo $RecordID; ?>\">
    <input type=\"submit\" name=\"Submit\" value=\"Submit\"></form>"
    ;

    ?>
    And it looks like this http://whitereview.co.uk/ups/contents4.php

    Well, at least I'm reading the images from the db OK, and the radio buttons seem to hold the id value. But how do I now pass this variable over?? I think I'm inserting the incorrect values into the submit values. Thats where I think I'm going wrong, because the browser output gives something like..
    http://whitereview.co.uk/ups/contents4.php?id=000001&action=%3C%3F+echo+000002%3B+%3F%3E&Submit=Submit
    when you press submit.
    Last edited by Ian M; Jul 1, 2002 at 18:05.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •