Jump to content

wrathican

Members
  • Posts

    446
  • Joined

  • Last visited

    Never

Everything posted by wrathican

  1. i have two arrays that look like this: $name1[0][value] $name2[0][value2] typical [key][value] right? now what i need to do is use the values of both arrays in a mysql query. how do i loop through the arrays using the values in the query? so the query would look something like this: update table set col='$name1 value' where col='$name2 value' i hope that makes sense. thanks
  2. ahh. that helps. thanks. would i be able to make the imageid and title as part of the same array? like image[] is the id number and image[][] is the title? so using the id as the key and title as the value?
  3. this puts the stuff from the db into an array? if im right then its not what i need. the while loop on my display page is fine, except for one thing. the main problem is my processing script. all my display script does is repeat some form fields. so if i had 3 items in my db it would look like this: <form> <img src="someimage" alt="sometitle"/><br /> <input type="hidden" name="imageid" value="2"/> <input type="text" name="title" /> <img src="someimage" alt="sometitle"/><br /> <input type="hidden" name="imageid" value="4"/> <input type="text" name="title" /> <img src="someimage" alt="sometitle"/><br /> <input type="hidden" name="imageid" value="7"/> <input type="text" name="title" /> <input type="submit" /> </form> so, i have multiple form fields called the same thing. i would have 3 fields called imageid, 3 called title. so what i need on my processing script is a way of getting the values of 'title' and 'imageid' to correspond with eachother. so the first imageid matches the title for it. i really hope im making sense.
  4. hmm, im really stuck on this. i have tried both examples and none have wond what i need. anyone have more suggestions?
  5. hey im making an image gallery and ive hit a technical hitch with the 'delete album' section i have my code so that the user selects an album to delte and the Id is sent to my processing script. the script then does the following this order. 1 - sees if there are any images in the images table that belong to that album -if not it deletes the album from the table if so: 2 - it gets the names of the files that belong to that album from the db 3 - it deletes (using unlink()) the file from the server but when i process the script every image from all the albums gets deleted. here is my script: <?php $alId = $_POST['album']; $imQuery = "SELECT * FROM won_picture WHERE pic_albumid='".$alId."'"; $imResult = query($imQuery); $imNumRows = numRows($imResult); if($imNumRows == 0) { //no images connected to the album. delete album $alQuery = "DELETE FROM won_album WHERE album_id='".$alId."'"; $alResult = query($alQuery); if($alResult) { //album was deleted $_SESSION['errorstate'] = 1; $errorarray[] = "Thank you. The album you selected has been deleted."; $_SESSION['errormessage'] = $errorarray; header('location: ../admin/index.php'); }else{ //album was not deleted $_SESSION['errorstate'] = 1; $errorarray[] = "Sorry, the album has not been deleted. Please try again."; $_SESSION['errormessage'] = $errorarray; header('location: ../admin/galleryadmin.php?func=delalbum'); } }else{ //images are connected to album while($row = mysql_fetch_array($imResult)) { $id = $row['pic_id']; $thumb = $row['pic_thumb']; $image = $row['pic_image']; $title = $row['pic_title']; $thDel = unlink('../images/thumbs/'.$thumb); $imDel = unlink('../'.$image); if($thDel) { //thumb was deleted if($imDel) { //image was deleted $_SESSION['errorstate'] = 1; $errorarray[] = "The image titled ".$title." has been deleted."; }else{ //image was not deleted $_SESSION['errorstate'] = 1; $errorarray[] = "The image titled ".$title." has not been deleted, but the thumbnail was."; } }else{ //thumb was not deleted $_SESSION['errorstate'] = 1; $errorarray[] = "The thumbnail image titled ".$title." has not been deleted and neither has the full size image.."; } } $_SESSION['errormessage'] = $errorarray; header('location: ../admin/galleryadmin.php?func=delalbum'); } ?>
  6. hey guys im trying to do a mass update in a db. the new values will be coming from a form. ive thought about how to do this going backwards. so starting with the actual update. for this i am going to use a foreach loop. so what i need to do is pass an array full of values from my php fom to my processing script. my form is displayed like so: <?php $query = "select * from table"; $result = mysql_query($query); ?> <form> <?php while($row = mysql_fetch_array($result)){ $img = $row['table_image']; $title = $row['table_title']; $imgId = $row['table_id']; ?> <img src="<?php echo $image; ?>" alt="<?php echo $title; ?>" /><br /> <input type="hidden" name="imageid" value="<?php echo $imgId; ?>" /> <input type="text" name="title" /> <?php } ?> <input type="submit" name="send" value="Send" /> </form> the only thing is i dont know how to start an array and store the values i need to in it. my array would(in a perfect world) look like this: $images['3']['title']; so '3' is the id of the image in the table, and 'title' is the title that the user would enter in the form input field. im just confused as to how i would display that in my form help? thanks in advanced
  7. im updating. both $title and $imgid are arrays so if i printed them out they would look like this. $title: [0] = title1 [1] = title2 [2] = title3 [3] = title4 and so on, and likewise with the $imgid [0] = 1 [1] = 2 [2] = 3 [3] = 4 so i want to update each database entry using the $imgid in the where clause of my update statment. i hope im making sense Thanks for the replies.
  8. hey, thanks for the reply. im sorry but i forgot to say i know how to update databases. what im looking to do i a mass update, so on my processing script it would, as i imagine it, look something like <?php $title = $_POST['title']; $imgid = $_POST['imageid']; while(!empty($title) { $query = "UPDATE table SET table_title='".."' WHERE table_id='".$imgid."'"; $result = mysql_query($query); } ?>
  9. hey peeps. what i have is a 'form' that shows a thumbnail with an input field underneath it. the form can have varying amounts of thumbnails. because of this what i need to do is update multiple entries in a database with the new values from the input fields. so my form would look something like this: $query = "select * from table"; $result = mysql_query($query); ?> <form> <?php while($row = mysql_fetch_array($result)){ $img = $row['table_image']; $title = $row['table_title']; $imgId = $row['table_id']; ?> <img src="<?php echo $image; ?>" alt="<?php echo $title; ?>" /><br /> <input type="hidden" name="imageid" value="<?php echo $imgId; ?>" /> <input type="text" name="title" /> <?php } ?> <input type="submit" name="send" value="Send" /> </form> so that displays a list of images with a box underneath it. what i need to do now is process the updates. how would i process it?
  10. hey guys, im trying to create next and previous functions for an image viewing script. the links for the next and previous images will be only viewable when a single image is being viewd. im trying to get the next id of an image from a db. heres what im trying to use so far. <?php //$currentAl = the album being viewed //$currentImg = current image being viewed function getNextImg($currentAl, $currentImg) { $query = "SELECT pic_id FROM won_picture WHERE pic_albumid='$currentAl'"; $result = query($query); $imgId = mysql_fetch_array($result) while ($imgId != $currentImg) { } return $nextImg; } ?> im a bit stuck on what i should write next. i gather all i need to do is get the numerical value of the position of current image id in the array, then add 1 to it and voila i have my next id in the sequence. i imagine the id's are stored in the array like so; $imgId[0] is the image id in the db of the first image $imgId[1] is the second image and so on.. so, my question is: how do i find out what posistion in the array the current image id is? and how do i get the next array value?
  11. if i were you i would use a while statement. <?php $query = ""; $result = mysql_query($query); while $row = mysql_fetch_array($result)) { //gets vars $image = $row['col']; //display images here like so ?> <img src="/images/<?php echo $image; ?>" alt="image" /> <?php } <? and please, if your going to make the site standards compliant DO NOT forget to add the alt="" tag.
  12. well if i understand you somewhat i would have a function that queries the database and returns the result. something like: <?php function queryDB($select, $table, $cols, $where, $order) { $query = "SELECT ".$select." FROM ".$table." WHERE ".$where." ORDER BY ".$order; $result = mysql_query($query); $array = mysql_fetch_array($result); return $array; } ?> so to call it, say: </php $result = queryDB("*", "users", "userid='".$userid."', "userid DESC"); $username = $result['username']; ?> i don't know if something like that would help?
  13. heh, thanks. i was just reading through the manual and i thought 'hang on, couldn't i set a session with the current URI at the end of my scripts?' and apparently i can thanks anyway!
  14. hey i was just wondering if there is an alternative way of seeing what the referring URI was in php other than HTTP_REFERER. this is mainly because my host does not have that variable enabled. (i think. its not listed when i call phpinfo()) but i would like to provide a bit of simplicity for my users so that if they are trying to access a page where they need to be logged in, they are taken to the login page and the referring URI is kept so i can forward them back to that page when they have successfully logged in. Thanks
  15. Thanks for the reply. I have since contacted my host and they do not have any PEAR packages installed on their servers, nor will they install them for me. so, my question remains. how do i accomplish the effect i am looking for without using and external packages?
  16. just a reminder! all headers in php need to be sent BEFORE ANY CONTENT. so you can have a massive if statement as deep as you want but if there is any 'echo' or html before the header() function. you get an error.
  17. Hey what i have done is created my own forum. its very basic and i wish to improve it further. now i have html special chars and mysql real escape string to prevent from injection attacks. what i want is the ability for a user to add html links <a></a> and images <img />maybe add the option to change font weight, colours and sizes. now with what i have at the moment my insert query would turn the '<' and '>' into < and > so it wouldn't display a link it would actually print <a href="link">link</a> and wouldn't be a clickable link. how would i go about getting this to be done. suggestions and links welcome Thanks
  18. ok, so ive been looking at my error log and it seems like the includes are not being included. however on my test.php page one of the includes is being included but not the other.
  19. so does that mean you guys are endorsing my post?
  20. what i would have is a page that can verify that a user is logged in and that a user's time to download hasn't expired. something like so: <?php //post the id of the file to download in the URL $downloadId = $_GET['id']; //check if the user is logged in if ($_SESSION['loggedin'] == 1) { //user is logged in //check if the user has not expired. //i would do this by using a table containing the date the user 'expires' //get the date from the table check it against todays date //im not quite sure how to compare dates so dont take this as gospel if ($tableDate < $todaysDate) { //display the link to the file to download }else{ //the user has expired echo 'your too late sucker!'; } }else{ //user is not logged in echo 'you need to be logged in silly'; } ?> hope it helps
  21. I am no way a mysql pro. or php pro. i dont understand your query. so lets make it a bit simpler. this is how i would do it: table structure id, product id, name, review, date, status. id: just an auto incremented integer. product id: the id of the product that should be contained in a separate table. name: name of person making the review. review: exactly what it says on the tin. date: date the review was made. status: 0 for pending, 1 for approved. firstly i would query the table for all the approved comments <?php $prodId = $_GET['productid']; $approvedQuery = "SELECT * FROM table WHERE status='1' AND product_id='".$prodId."'"; // a status of 1 = approved $approvedResult = mysql_query($approvedQuery); $approvedNumRows = mysql_num_rows($approvedResult); ?> then query for the pending reviews <?php $pendingQuery = "SELECT * FROM table WHERE status='0' AND product_id='".$prodId."'"; // a status of 0 = pending $pendingResult = mysql_query($approvedQuery); $pendingNumRows = mysql_num_rows($approvedResult); ?> then you can echo it as follows: <?php $totalReviews = $approvedNumRows + $pendingNumRows; echo 'This product has a total of '.$totalReviews.' reviews.<br >'; echo $approvedNumRows . ' of these reviews have been approved.<br />'; echo $pendingNumRows . ' of these reviews are awaiting approval.'; ?> i hope this helps..
  22. all i can do reccomend some easy reading. W3Schools is a good place to start: http://www.w3schools.com/php/php_forms.asp and this is about a login system, as i didnt quite understand what was going on in your script: http://phpeasystep.com/workshopview.php?id=6 Good Luck!
  23. hey guys. i decided to make a basic 'template' and include my header and footer around my content. the footer is not displaying how i imagine it should. the whole page should look like this: http://www.ls12style.co.uk/projects/random but the page does not display the right hand column. as can be seen here: http:www.test.ls12style.co.uk/test.php i duplicated my index page from the '/projects/random/' which has some php retrieving some data from a DB. This page does not show at all. as can be seen here: http://www.test.ls12style.co.uk/index.php this is the header: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="/random.css"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>LS12 Community :: <?php echo $page_title ?></title> </head> <body> <div id="wrapper"> <div id="header"><img src="/images/logo.png" alt="Random Website" /></div> <div id="content-wrapper"> <div id="content"> <div class="in"> <h2><?php echo $page_title ?></h2> This is my footer: </div> </div> </div> <div id="left"> <div class="in"> <h2>Navigation</h2> <ul class="navi"> <li>&#187; <a href="/index.php">Home</a></li> <li>&#187; <a href="/about.php">About Us</a></li> <li>&#187; <a href="/gallery.php">Gallery</a></li> <li>&#187; <a href="/contact.php">Contact Us</a></li> <li>&#187; <a href="/blogs.php">Blogs</a></li> </ul> <br /> <?php if ($_SESSION['loggedin'] == "yes") { //display members nav ?> <h4>Members Section</h4> <p>Welcome, <?php echo $_SESSION['username']; ?>!</p> <ul class="navi"> <li>&#187; <a href="/members/galleryadmin.php">Gallery Admin</a></li> <li>&#187; <a href="/members/forum.php">Forum</a></li> <li>&#187; <a href="/members/details.php">Change Details</a></li> <li>&#187; <a href="/members/password.php">Change Password</a></li> <li>&#187; <a href="/members/announce.php">Announcements</a></li> <li>&#187; <a href="/members/blogadmin.php">Blogging</a></li> <li>&#187; <a href="/functions/userfunctions.php?func=logout">Log Out</a></li> <?php if ($_SESSION['level'] == 1) { ?> <li>&#187; <a href="/admin/index.php">Admin</a></li> <?php } ?> </ul> <?php }else{ //display login form ?> <form action="/functions/userfunctions.php?func=login" method="post" id="login"> Username:<br /> <input type="text" name="username" /> <br /> Password:<br /> <input type="password" name="password" /> <br /> <input type="submit" name="login" value="Login" /> &#187; <a href="/register.php">Register</a> </form> <?php } ?> </div> </div> <div id="right"> <?php //get recent/site statistics //members $mQuery = "SELECT * FROM ls12_users"; $mResult = query($mQuery); $mNumRows = numRows($mResult); //recent topics $tQuery = "SELECT topic_id, topic_title FROM ls12_topic ORDER BY topic_lastpost DESC LIMIT 2"; $tResult = query($tQuery); //forum posts $pQuery = "SELECT * FROM ls12_post ORDER BY post_id DESC"; $pResult = query($pQuery); $pNumRows = numRows($pResult); //galleries $gQuery = "SELECT * FROM ls12_album ORDER BY album_id DESC LIMIT 2"; $gResult = query($gQuery); $gNumRows = numRows($gResult); //pictures $iQuery = "SELECT * FROM ls12_image ORDER BY image_id DESC"; $iResult = query($iQuery); $iNumRows = numRows($iResult); //blogs $bQuery = "SELECT * FROM ls12_blog ORDER BY blog_id DESC"; $bResult = query($bQuery); $bNumRows = numRows($bResult); ?> <div class="in"> <h2>Recent Updates</h2> <h4>Galleries</h4> <?php while ($gRow = mysql_fetch_array($gResult)) { $alId = $gRow['album_id']; $alName = $gRow['album_name']; $alImg = $gRow['album_image']; $alUid = $gRow['album_ownerid']; ?> <p>&#187; <a href="/gallery.php?func=viewal&alid=<?php echo $alId; ?>"><?php echo $alName; ?><br /> <img src="/images/album/<?php echo $alImg; ?>"></a><br /> <?php $oName = getUsername($alUid); echo 'By '.$oName.'</p>'; } ?> <h4>Forum Posts</h4> <ul> <?php while ($tRow = mysql_fetch_array($tResult)) { $topicId = $tRow['topic_id']; $topicTitle = $tRow['topic_title']; ?> <li>&#187; <a href="/members/forum.php?func=viewtopic&topicid=<?php echo $topicId; ?>"><?php echo $topicTitle; ?></a></li> <?php } ?> </ul> <h4>Blogs</h4> <?php //list last 5 blogs if ($bNumRows != 0) { echo "<ul>"; while ($bRow = mysql_fetch_array($bResult)) { $blogId = $bRow['blog_id']; $blogTitle = $bRow['blog_title']; $blogAuth = $bRow['blog_authorid']; //get username $bUserName = getUsername($blogAuth); ?> <li>&#187; <a href="/blogs.php?blogid=<?php echo $blogId; ?>"><?php echo $blogTitle; ?></a> <ul> <li class="nested">by <?php echo $bUserName; ?></li> </ul> </li> <?php } echo "</ul>"; }else{ echo "No blogs yet"; } ?> <h4>Statistics</h4> <p>Members: <?php echo $mNumRows; ?><br /> Albums: <?php echo $gNumRows; ?><br /> Pictures: <?php echo $iNumRows; ?><br /> Forum Posts: <?php echo $pNumRows; ?><br /> Blogs: <?php echo $bNumRows; ?></p> </div> </div> <div id="footer">Copyright © 2008 <a href="http://members.ls12style.co.uk">Members.LS12Style.co.uk</a> Web design by <a href="http://www.ls12style.co.uk">Ashley Broadley</a></div> </div> </body> </html> <?php include "/includes/close.php"; ?> and this is my final page(that doesnt display anything): <?php //Included files include "/includes/misc.php"; include "/includes/opendb.php"; include "/includes/functions.php"; //start session session_start(); //breadcrumb $page_title = "Welcome"; include "/includes/header.php"; ?> <p>Welcome to the brand new LS12Style.<br /> This is still THE place for us guys to share our pictures, videos and messages. Feel free to explore, take a peek at some of the pictures from various parties/festivals/random places.<br /> <br /> Fancy making your own picture album? Well, click <a href="register.php">here </a>to register!<br /> Unsure about registering? Want to find out why you should register? Well then, click <a href="benefits.php">here</a> to find out more!</p> <?php $query = "SELECT * FROM ls12_announce ORDER BY ann_date DESC LIMIT 5"; $result = mysql_query($query); $numRows = mysql_num_rows($result); if ($numRows != 0) { echo '<h2>Announcements</h2>'; while ($row = mysql_fetch_array($result)) { $annId = $row['ann_id']; $title = $row['ann_title']; $message = $row['ann_message']; $userId = $row['ann_ownerid']; $odate = $row['ann_date']; $tdate = strtotime($odate); $date = date("F j, Y, g:i a", $tdate); $queryName = "SELECT user_username FROM ls12_users WHERE user_id = '".$userId."'"; $resultName = query($queryName); $arrayName = mysql_fetch_array($resultName); $userName = $arrayName['user_username']; ?> <div class="announce"> <h3><?php echo $title ?></h3> <p> <?php echo $message ?><br /> <br /> Posted by <?php echo $userName . " on " . $date; ?><br /> </p> <?php include "/includes/footer.php"; ?> any idea why this is happening?
  24. you dont need to have a <br /> in the text area. when you type something in a textarea and press enter/return to put text onto a new line, the browser/parser/whatever adds a new line 'character' in the position of where enter was pressed. the nl2br function simply replaces the new line 'characters' with an xhtml standards compliant line break. search for it in the manual
×
×
  • 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.