Jump to content

Box

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Everything posted by Box

  1. fantastic! I've managed to get it right thanks to your code which wasnt too far off what I needed. just had to add in the group by and change the id to catid the working code being: SELECT c.*, COUNT(n.category) AS newsCount FROM categories AS c LEFT JOIN news AS n ON (n.category = c.catid) GROUP BY c.catname ORDER BY c.catname ASC
  2. Not really sure on how to do this as i'm not too great with mysql. I have 2 tables categories and news. news has a unique id and a category id categories has the catagory id and the name to be used on it. Im trying to make some stats that lists all the category names and the number of times it has been used in the news table This is my latest attempt at it. SELECT COUNT( * ) AS rows, news.category, categories.catname FROM news, categories GROUP BY category ORDER BY category WHERE catid=category
  3. whenever i do this i use the ternary operator <td height="40" align="right" valign="top" bgcolor="#FFFFFF">Time Type:<span class="style1">__</span></td> <td align="left" valign="top"><label> <?php $result = mysql_query("SELECT type, visit_id FROM visit_type "); ?> <select name="visit" id="visit"> <?php while($row = mysql_fetch_array($result)) { ?> <?php echo '<option value=' . $row[visit_id] . $row[visit_id]==$whatever ? " selected" : ""'> ' . $row['type'] . ' </option> '; ?> <?php } ?> </select> </label></td> make sure to set $whatever to your checked item which will probably be another mysql query
  4. I've just realised the error! my second line of php was wrong $memlist="SELECT * FROM members WHERE id='$_GET[cid]'"; should have be $memlist="SELECT * FROM members WHERE id='$_POST[cid]'"; thanks for the suggestions though
  5. heres the snipit of code and it is in<? ?> brackets if ($_POST["cid"]) { $memlist="SELECT * FROM members WHERE id='$_GET[cid]'"; $result=mysql_query($memlist); $row=mysql_fetch_array($result); if ($curlevel < 4) { die("You do not have access to do this"); } elseif ($curlevel <= $row['userlevel']) { die("You cannot change a password of the same level or higher"); } else { mysql_query("UPDATE members SET password='".md5($_POST['cpw'])."' WHERE id='".$_POST['cid']."'")or die( mysql_error()); echo("Password for user ".$row['username']." changed"); } // end of update user level check } the code works and the password is changed but the line echo("Password for user ".$row['username']." changed"); omits the username there is a username field in the database that isnt blank any ideas im completely stumped as this would normally work fine.
  6. that line is between some earlier <? brackets i only posted the line that called it, the last 2 bits of code dont directly follow each other. it was jsut to show the variable names of the form and the line that calls the main function
  7. I'm making a admin system in which a few pages will have the ability to upload files to various sections so to make things neat and small i'd like to make an upload function to call rather than having the same/similar code in multiple pages Below is the code i've wrote which worked before it was a function but not after. I think my issue is passing the data to the function function takefile($filename, $newname, $target_path, $thumb) { $ext =explode('.', $_FILES[$filename]['name']); $ext = ".".$ext[count($ext)-1]; $target_path = $target_path.$newname.$ext; if(move_uploaded_file($_FILES[$filename]['tmp_name'], $target_path)) { echo "The picture ". basename( $_FILES[$filename]['name']). " has been uploaded<br />"; //make profile pic if ($thumb == "Y") { //not important right now } } else { echo "There was an error uploading the picture, please try again!<br />"; } } the form and calling parts of the code are: <input name="aim" type="file"> <br /><a href="managecategories.php?dp=<? echo($row['catid']); ?>">[delete current picture]</a> </td> takefile('aim','test','..images/buttons/','N'); can someone please tell me how I can do this? Or see whats going wrong? Thanks
  8. yeah i want all 3 Ie firstname: billy lastname kidd nickname the would show "billy the kid" I only want the expression to be: $row['nickname'] to basically check if it has anything in it. I guess I need to split it into lines to make it work then? $name = $row['firstname']." "; $name .= $row['nickname']!=""?"'".$row['nickname']."' ":""; $name .= $row['lastname']; is working fine. and now shows the nickname with '' around it. ie billy 'the' kid im still not sure as to why the other code didnt work. even if the exression was always true it should have just forced the nickname to be shown (and if there wasnt one just a double space in the name) Te fact it was either the nickname or nothing was the main confusing part thanx for the help though ill try remember the name of it ok upon reading again i now realise that the firstname was never shown as it was included as part of the expression, and the reason the surname was never shown is because it was art of the false statement. what i has wanted was: expr: $row['nickname'] true_part: $row['nickname']." " false_part: "" i guess all on one line was just too much O_o
  9. Sorry I don't know the name of thing function(?) but i do know how to use it i have a table with firname lastname and nickname in it not everyone has a nickname and I don't want it to show a double space and have it forced in so put in a check to see if it exists. At the moment it currently only shows the nickname which has got me very confused. Id rather not use actual ifs and elses as I know this should work. Im assuming ive got an extra character in there somehwree or a " in the wrong place maybe? the line is: $name = $row['firstname']." ".$row['nickname']?$row['nickname']." ":"".$row['lastname']; any help? Thanks
  10. <?php include("dbconnection.php"); if (!$_GET['state'] { $sql = "SELECT name, abbreviation FROM resorts ORDER BY name ASC; $rs = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($rs)) { $output .= "<ul>"; while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { $output .= "<li><a href=resorts.php?state=$row[abbreviation]>$row[name]</a></li>"; } $output .= "</ul>"; } print $output; } else { $state = $_GET['state']; if(isset($state) { include($state . '.php'); //ex. This would display the contents of ct.php } else { include("index.php"); } } ?> like that? check to see if ?state was passed, if it was the don't show the list of links you have otherwise include the states page.
  11. just as a bit of extra info basename($_SERVER['PHP_SELF']) will remove the directories from the result and just give you index.php or news.php if(basename($_SERVER['PHP_SELF']) = 'index.php') { echo 'I am index.php'; }
  12. not really sure what your getting at. you can use an if to check what the variable is and then display various pages: ie: if($_GET['resort']) { echo ("The ".$_GET['resort']." is a nice place to go on holiday"); } else if ($_GET['caravanpark']) { echo ("Caravan parks are less fun, especially ".$_GET['caravanpark']); }
  13. never mind! ive fixed it, i had a typo! atatchEments. whoops! thanks anyway
  14. I seem to be having multiple issues with this. //deal with the uploaded file if($_FILES['attachment']['name']) { $target_path = "../attachments/"; $target_path = $target_path . mysql_insert_id(); if(move_uploaded_file($_FILES['attachement']['tmp_name'], $target_path)) { echo "The attached file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br />"; } else{ echo "There was an error uploading the file, please try again!<br />"; } } //stop dealing with the uploaded file I am wanting the file to be named whatever the new auto id row is to stop any duplicate files being uploaded etc and this is a bit neater than a timestamp. when I echo'd: $_FILES['attachment']['name'] and $target_path . mysql_insert_id(); they came back empy but $_FILES['attachement']['tmp_name'] gives the temp filename. The code never actually enters the if statement (I commented it out and tested the code inside the if statment to check if that was sound but ran into the above problems) Any ideas? Im hoping for something simple thanks
  15. you just need to actually print the variable ie: Event:<input type="text" name="Event" value="<?php echo($name); ?>" /> <P>
  16. :'( Such a rookie mistake. I assumed the php was wrong and completely overlooked the html form itself. It works absolutely fine now. I think I'll go sulk in the corner for a while now Thanks
  17. This should be very very simple and its been driving me crazy since Thursday night. The directory is chmodded to 777 so its not that my form is: <table> <tr> <form action="managemusic.php" method="post"> <td>Track Name/Comp: </td><td><input type="text" name="name"/></td></tr> <td>Artist/Squad: </td><td><input type="text" name="artist" /></td></tr> <td>Filename: </td><td><input type="file" name="uploadedfile" /> </td></tr> <tr><td colspan="3" align="center"><input type="submit" value="Add Song"/></td?</tr> </form> </table> and my code to upload the file from this form is: move_uploaded_file ($_FILES['uploadedfile'] ['tmp_name'], "../player/$_FILES['uploadedile'] ['name']"); I cannot for the life of me get the file to upload or even be acknowledged. I've tried echoing the variables out and they show nothing. Am I at a lost cause and have spent so many hours googling and playing with the code, this is the 3rd version and the most basic (less code there is, the less to go wrong with it, ill add in the error checking again once I get the main part working! some please put me out of my misery
×
×
  • 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.