Jump to content

fife

Members
  • Posts

    381
  • Joined

  • Last visited

Everything posted by fife

  1. fife

    if statement

    yes it echos the address of the user.
  2. I have a simple if statment issue. Here is the code <?php $address = $User['address_l1']; if (empty($address)) { echo "You have not entered an address";} else {echo "You Have entered an address";} ?> The variable $address in this case is not empty so it should echo you HAVE entered an address but its echoing NOT. Can somebody please explain why this is not working?
  3. If I change that line to while then I get an error from the server that states theres an unexpected ; in that line
  4. I have this code which gets in an array all the current activities i'm a member of. I then want to use my array time and time again. the problem I have is im already using it and because I dont know enough php I cant figure out how to re-use it. Here is the code I have...... <?php for($i = 0; ($CP = mysql_fetch_assoc($Link) && $i < 3; $i++ ){ ?> <table width="50" border="0" cellpadding="0" cellspacing="0" id="list_of_clubstbl"> <tr> <th width="34" scope="col"><a href="<?php echo $CP['clubID'];?>"><img name="<?php echo $CP['cover'];?>" src="" width="50" height="50" alt="<?php echo $CP['name'];?> " /></a></th> </tr> <tr> <td><?php if ($CP['permission']=='1') {echo " <a class=\"ownertext\" href=\" {$CP['clubID']}\">{$CP['name']}</a>";} elseif ($CP['permission']=='2') {echo "<a class=\"admintext\" href=\" {$CP['clubID']}\">{$CP['name']}</a>>";} elseif ($CP['permission']=='3') {echo "<a class=\"stafftext\" href=\" {$CP['clubID']}\">{$CP['name']}</a>";} elseif ($CP['permission']=='4') {echo "<a class=\"membertext\" href=\" {$CP['clubID']}\">{$CP['name']}</a>";} ?></td> </tr> </table> <br/> <?php } ?> Where I have used ($CP = mysql_fetch_assoc($Link) && $i < 3; $i++ ) I understand I'm fetching the array and limiting it by 3. Once I have done mysql_fetch_array on the $Link I see it can not be used again. Is there a way to create this loop so I'm not limiting the TOTAL array by 3. Does that even make sense?
  5. ok I have updated the query to look as follows but still nothing is displayed in the 2nd box. $qCat = "SELECT * FROM category"; $rCat = mysql_query($qCat); $Cat = mysql_fetch_assoc($rCat); <td>1st favourite</td> <td><select name = 'fav_1'>"; while($Cat) { echo " <option value='{$Cat['catID']}'>{$Cat['categorys']}</option>";} echo " </select></td> </tr> <tr> <td>2nd favourite</td> <td><select name = 'fav_2'>"; while($Cat){ echo " <option value='{$Cat['catID']}'>{$Cat['categorys']}</option>";} echo "</select></td> </tr>
  6. I would but I need 5 separate entries from the same array entered into my database
  7. how do you use a while loop 2 twice from one assoc array? eg <tr> <td>1st favourite</td> <td><select name = 'fav_1'>"; while($Cat = mysql_fetch_assoc($rCat)) { echo " <option value='{$Cat['catID']}'>{$Cat['categorys']}</option>";} echo "</td> </tr> <tr> <td>2nd favourite</td> <td><select name = 'fav_2'>"; while($Cat = mysql_fetch_assoc($rCat)) { echo " <option value='{$Cat['catID']}'>{$Cat['categorys']}</option>";} echo "</td> </tr> The first one works fine but the second is empty.
  8. Thank you very much the query works great now!
  9. ok I now have an error to work with. can anyone make sense of this? You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `clubs` WHERE `cat` IN('22', '20', '17', '26', '25') OR `area' at line 1 //for this query $Adds = sprintf("SELECT `name`, `cover`, `cat`, `subcat`, `area`, `county`, `thumbsup`, FROM `clubs` WHERE `cat` IN('%s', '%s', '%s', '%s', '%s') OR `area` = '%s' OR `county` = '%s' ORDER BY rand() LIMIT 5", $User['fav_1'],$User['fav_2'],$User['fav_3'],$User['fav_4'],$User['fav_5'], $User['area'], $User['county']); $adverts = mysql_query($Adds) or die(mysql_error()); while($CP = mysql_fetch_assoc($adverts)){ echo "{$CP['name']}<br/>"; }
  10. Ok. I have made the changes and read up on the new commands you have sent me. I re-wrote the query to match but still it echo's nothing. I even tried just to echo $adverts but it seems to be empty. Which would suggest the query is wrong. I tried mysqli_query and mysql_query but nothing. Let me explain again what I want coz maybe im going about this the wrong way. // ok so I want to find all the clubs which cat of the club is equal to the users top 5 favourite categorys. Also in the query the returned clubs must be in either the same town or county . $Adds = sprintf("SELECT `name`, `cover`, `cat`, `subcat`, `area`, `county`, `thumbsup`, FROM `clubs` WHERE `cat` IN('%s', '%s', '%s', '%s', '%s') OR `area` = '%s' OR `county` = '%s' ORDER BY rand() LIMIT 5", $User['fav_1'],$User['fav_2'],$User['fav_3'],$User['fav_4'],$User['fav_5'], $User['area'], $User['county']); $adverts = mysqli_query($Adds) or die(mysql_error()); // I then just want to display the names of these clubs for now. At the minute with the user im using it should display one club! while($CP = mysql_fetch_assoc($adverts)){ echo "{$CP['name']}<br/>"; } // that query seems to echo nothing but I know it works because if I write........ $query = mysql_query("SELECT * FROM `clubs` WHERE `cat` = ".$User['fav_1']." ORDER BY rand() LIMIT 5") while ($result = mysql_fetch_assoc($query)) { echo "{$result['name']}<br/>"; } //then my query comes back with a name. I have check that my town and county between the club and the user are the same. So does anybody have any idea whats wrong or maybe another way to write the query to incorporate the above?
  11. ok I used the code given and it seem to not be doing anything. I dont think it is wrong because it does not throw any errors but here is what I have. It should come back with one name.... $Adds = mysql_query ("SELECT name, cover, cat, subcat, area, county, thumbsup, FROM clubs WHERE cat IN('%s', '%s', '%s', '%s', '%s') AND area = '%s' OR county = '%s' ORDER BY rand() LIMIT 5", $User['fav_1'],$User['fav_2'],$User['fav_3'],$User['fav_4'],$User['fav_5'], $User['area'], $User['county']); while($CP = mysql_fetch_assoc($Adds)){ echo "{$CP['name']}<br/>"; }}
  12. that looks much better. I have never seen it written '%$' before. thats really good thank you. I will try it now and let you know how it goes.
  13. looks right to me. Here is one i use all the time { mail($userInfo['email'],"Validation Link From website","Dear ".$userInfo['username'].",\n\nThank you for signing bla bla bla");}
  14. //is this correct $qAdds = "SELECT name, cover, cat, subcat, thumbsup, FROM `clubs` WHERE `cat` IN = ('".$User['fav_1']."', '".$User['fav_2']."', '".$User['fav_3']."', '".$User['fav_4']."', '".$User['fav_5']."') AND `area` = ".$User['area']." AND county = ".$User['county']." ORDER BY rand() LIMIT 5"; //??
  15. Im just asking if there is a neater way to write the statement. say this or this or this or this and this and this just seems really long winded. Is it possible to write it more cleanly or have I written it the best way you can?
  16. Hi Right here is what I'm trying to do. I have in my members table 5 fields called fav_1 to fav_5. These fields are just category ID's. In my group table I have also got a catID (cat) field. Im trying to make a query which will match at random the group cat to any of the members top 5 where the area first and county second are the same and limited by 5. I also want it to order it by fav_1 and down the scale. I have wrote the query but it just looks really messy. Is there a nicer way to do this? $qAdds = "SELECT name, cover, cat, subcat, thumbsup, FROM `groups` WHERE `cat` = ".$User['fav_1']." OR `cat` = ".$User['fav_2']." OR `cat` = ".$User['fav_3']." OR `cat` = ".$User['fav_4']." OR `cat` = ".$User['fav_5']." AND `area` = ".$User['area']." AND county = ".$User['county']." ORDER BY rand() LIMIT 5";
  17. yes each email will be populated with a different request so the emails need to be individual to each person sent to. Basically it is a script I need which allows one person to send out 5 emails at a time inviting people to join the site. Each email needs to be sent separately though because there is a unique 25 digit key within each one which I use to identify them when they click the link!
  18. I have a simple tell a friend script that works fine for the moment. its a simple.... $email = $_POST['email']; { mail("$email","Request","Dear Member, \n\nbla bla bla bla bla\n\n\n\n"); } I have an issue now though. The form now needs to be able to send 5 separate emails to 5 different people. How would this be done or is this even possible with the code I have? $email1 = $_POST['email1']; $email2 = $_POST['email2'];
  19. sorry. I have found the answer after lot of searching str_replace("\n", "\n<br />\n"
  20. I have a field in my database called `intro` In this field the user has entered spaces, different paragraphs and "" When it was entered into the field it was run through trim and mysql_real_escape_string. when its echoed I am just using echo "member['intro']; How do I make it display like it was entered? Is there a function for this?
  21. I have written this code but im not used to echoing html in php so I have errors. echo " <option value= '{$county['county']}'" if ($User['county'])==$county['county']) {echo "selected";} echo">{$county['county']}</option>"; } the server error is; syntax error, unexpected T_IF, expecting ',' or ';' Can somebody please point out how I have written it wrong?
  22. OK after a lot of research I see I was going about this all wrong. I have to do a inner join. So I have done one, but there is an error as my query is a little more complicated than the practise ones. I have to do mine based on the current user logged in! Can somebody please explain what I have done wrong? the code $qLink = mysql_query("SELECT link.memberID, link.permission, link.clubID, clubs.clubID, clubs.name, FROM `link` INNER JOIN `clubs` ON link.clubID=clubs.clubID WHERE link.memberID = ".$User['memberID']."") or die(mysql_error()); for($i = 0; ($CP = ($qLink)) && $i < 3; $i++ ){ ?> <tr> <th scope="col"><img name="" src="" width="32" height="32" alt="" /></th> <th scope="col"><?php echo $CP['name']; ?><span class="ownertext"> <?php echo $CP['permission']; ?></span></th> <?php } ?> The Error; You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `link` INNER JOIN `clubs` ON link.clubID=clubs.clubID WHERE link.memberID =' at line 1
  23. sorry that last post was wrong where it says //from link table. Its not at all its from the permission table
  24. Ok i have been after the solution for this for a while and I have finally got it in a state where it is producing results but....... they are wrong so I will start from the beginning with what I have and what I am trying to do. I have these tables Members Id Name Clubs ID Name Permission ID Name Link MemberID PermissionID ClubID When a member joins a club thier ID ant the ID of the club are entered into the link table along with their permission (as a number) so MemberID PermissionID ClubID 01 02 01 I have a loop which is going to echo the clubs a member is a part of. So for my querys function GetUser($user) { $qFindUser = "SELECT * FROM members WHERE email = '$user'"; $rFindUser = mysql_query($qFindUser); $UserInfo = mysql_fetch_array($rFindUser); return $UserInfo; } function GetLinkByMemberID($link) { $qLink = mysql_query("SELECT * FROM link WHERE memberID = '$link'"); $Link = mysql_fetch_array($qLink); return $Link; } function GetClub1($clubs) { $qFindClub = mysql_query("SELECT * FROM clubs WHERE clubID = '$clubs'"); return $qFindClub; } function GetPermission($per) { $qPermission = mysql_query("SELECT * FROM `permissions` WHERE permissionID = '$per'"); $permission = mysql_fetch_array($qPermission); return $permission; } $User = GetUser($_SESSION['Username']); // returns as array from the login details all member details $Link = GetLinkByMemberID($User['memberID']); // returns as a fetch array all clubs the member is a part of $Club = GetClub1($Link['clubID']); // returns as the query $permission = GetPermission($Link['permission']); //returns as array so I can echo the permission word not ID Now the loop is limited by 3 so <?php $Club = mysql_fetch_array($Club); $stack3 = ($Club+$Link); for($i = 0; ($CP = ($stack3)) && $i < 3; $i++ ){ ?> <tr> <th scope="col"><img name="" src="" width="32" height="32" alt="" /></th> <th scope="col"><?php echo $CP['name']; //from the club table ?><span class="ownertext"> <?php echo $CP['permission']; //from the link table ?> The problem I'm having the the loop is returning the first record its selects 3 times and not echoing each club once. I have worked on it for so long I can no longer make sense of it. Can anyone see my errors and point out just how to fix it? Im guessing it involves something to do with how Im finding my permission but I really dont know. As im sure you can see from the code Im a php beginner so Im struggling to make sense of this.
  25. Ok well I have re-written it now to look like this.. function check_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); $data = mysql_real_escape_string($data); return $data; }; Now when returning data from the form I run it through the function before it goes into the database. Is this best practise. The code seems so small leaner but some of the functions no matter how many times I read about them they just seem to make no sense.
×
×
  • 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.