SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Edit info link for listed pictures

    hello all,


    I'm working on code for listing pictures from database.
    I got the listing, in next step I want to create link "edit info"
    for each of the listed items.
    What should I put in editing.php so it will edit each picture?

    Here is my code for listing

    Code:
    $result2 = mysql_query("SELECT * FROM tbl_usr_gal_pic where usr_email ='$email1' "); 
    
    while($row2 = mysql_fetch_array($result2) )
      {
    
    echo " 
    
    <TABLE BORDER=0 CELLPADDING=2>
    <TR>
        <TH ROWSPAN=8 BGCOLOR='#99CCFF'>"; echo '<img src =\'' . $row2[4] .'\' width="140" height="140" border="0" >'; echo "</TH>
    	<td></td>
        <TD><p style='font-size:small; font-weight:bold;'>"; echo $row2[2]; echo "</p> </TD> <TD> </TD> <TD><p style='font-size:x-small;'>";?> <a href='editing.php'> <?php echo " Edit Information</a></p></TD>
        </TR>
    
    <TR>
    	<td></td>
        <TD>";
    
    if  ( $num4 == "1" ) {
     echo  $num4;echo "$nbsp photo";}
    	else {
     echo $num4;echo "$nbsp photos"; }
    
    
    	echo " <br> created on "; echo $row2[7];   echo" </TD> <TD> </TD>
        </TR>
    <TR>
        <td></td>
        <TD>  </TD>
    	 <TD> </TD>
        </TR>
    <TR>
    	<td></td>
        <TH rowspan=4><p style='font-size:small; font-weight:bold;'> some text will be here</p>  <p style='font-size:small; font-weight:normal;'>Statement will be here</p> </TH>
    	 <TD></TD>
    	<td></td>
        </TR>
    <br>
    </TABLE>

    Thanks

  2. #2
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need to assign each link on every picture with a unique id and pass that id to editing.php so you'll know w/c picture or item to edit. And naturally you need a form in editing .php so it can process the data and store it in the database.

    Also consider separating css styles from your codes it looks too cramped up already considering you're using tables.
    Don't Panic

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes,

    echo $row2[2]; is a unique pic name.

    How can I pass that to the editing.php, so it will know which one it suppose to edit ?

    Thanks !!

  4. #4
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you'll have to pass it to edit.php like so(using get)

    Code PHP:
    <a href=editing.php?item=<? echo $row2[2]?>>

    on the edit.php get the passed var like so
    Code PHP:
    $pic_to_edit = $_GET['item'];
    echo $pic_to_edit;
    //do the form here
    Don't Panic

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok,

    that was helpful a lot !!
    Thanks,
    let's say there is some form and I need to update 2 fields based on the selection,
    so how to create mysql query so records can be updated based on $pic_to_edit
    ?

    mysql_query ( "INSERT INTO tbl_pictures ( statement, year_of_the_pic ) VALUES ( '$statmnt', '$gyear' ) WHERE pic_name = '$pic_to_edit' ") or die (mysql_error()); echo "success";

    Above query doesn't work,
    how can I fix that?


    Thanks again !!

  6. #6
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kabucek View Post
    ok,

    that was helpful a lot !!
    Thanks,
    let's say there is some form and I need to update 2 fields based on the selection,
    so how to create mysql query so records can be updated based on $pic_to_edit
    ?

    mysql_query ( "INSERT INTO tbl_pictures ( statement, year_of_the_pic ) VALUES ( '$statmnt', '$gyear' ) WHERE pic_name = '$pic_to_edit' ") or die (mysql_error()); echo "success";

    Above query doesn't work,
    how can I fix that?


    Thanks again !!
    When you use insert it will ...you guess it "insert" another record. It should be update.

    UPDATE table SET statement = '$statmnt', year_of_the_pic = '$pic_to_edit' WHERE pic_to_edit = $pic_to_edit

    I'm kinda confuse on what fields in your databse you are updating. But I presumed that in your form you have a hidden field with the $pic_to_edit as the value.

    I'll give an exact code if you post the exact field you are editing in your database
    Don't Panic


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
  •