Jump to content

Chris.P

Members
  • Posts

    34
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Chris.P's Achievements

Member

Member (2/5)

0

Reputation

  1. Let's see if I can explain this ok.. Basically I have a site and the page product categories use dynamically created URL's. I want to use these URL's to put on my products so I can list all the categories each product is in. But, as these URL's are not stored anywhere I'm not sure how to go about calling them. Is the best way going to be to modify the site to store the page URL's in MySQL? Or could they be stored within variables in PHP? A little guidance would be great! Thanks in advance
  2. Thanks Nightslyr for the advice. The code was actually written by someone else and I'm editing it as I'm learning so didn't spot what you mentioned. I'll get it changed! Thanks for the solution too I'll give it a go
  3. I've written the following code that grabs the meta description set in the MySQL database. Basically what I want to do it check the $metadescription variable and if it's empty run another query to put a different piece of information from the database in there. It seems like another if statement would be needed? function metadescription() { global $db; //checks if it's our category page if(isset($_GET['cat_id'])) { $cat_id = mysql_real_escape_string($_GET['cat_id']); $query = "SELECT * FROM categories WHERE cat_id = '$cat_id'"; $result = $db->query($query); $result = $db->fetchrow($result); $metadescription .= $result['cat_meta_description']; } return htmlentities($metadescription); }
  4. I have the following code. Basically I'm trying to count the amount of colours returned in the $colour variable. What I have is always returning 1, any ideas why? $colour = $db->query("SELECT * FROM colours WHERE prod_id = ".$row['prod_id']." AND LENGTH(col_image_1) > 0 ORDER BY col_rank ASC LIMIT 1"); $colourcount = mysql_num_rows($colour); if($db->numrows($colour)) { $colour = $db->fetchrow($colour); } else { unset($colour); } echo $colourcount;
  5. Ok, so I've read a few tutorials of OOP and have a basic understanding of how it works but where is it generally handy? I have a basic site created with PHP that consists of a form that submits data to MySQL and then lists the data from the MySQL database on another page. Kind of like a little online planner. I don't see how me converting my site to use OOP would help here. Maybe it's best for more complex situations such as a shopping cart where data needs to be shared across multiple pages?
  6. Thanks for the reply! I'm a bit of a noob so I'm going to have to study what you just said a little more before I get my head around it. I'm currently doing each page like this which looks like a different way of outputting to how you did it. $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (mysql_num_rows($result) > 0) { echo "<table>"; echo "<tr class='titles'>"; echo "<td><h2><a href='note.php?order=date_added'>Date Added</a></h2></td>"; echo "<td><h2><a href='note.php?order=note_description'>Note Description</a></h2></td>"; echo "<td><h2><a href='note.php?order=added_by'>Added By</a></h2></td>"; echo "<td><h2><a href='note.php?order=note_status'>Done?</a></h2></td>"; echo "<td><h2>Delete</h2></td>"; echo "</tr>"; while($row = mysql_fetch_assoc($result)) { $itemid = $row['note_id']; echo "<tr class='$rowclass'>"; //echo "<td><p>".$row['item_id']."</p></td>"; echo "<td>".$row['date_added']."</td>"; echo "<td>".$row['note_description']."</td>"; echo "<td>".$row['added_by']."</td>"; echo "<td>".$row['note_status']."</td>"; echo "<td><a href='?deleteitem=$itemid' onclick='return delete_me()' value='delete me box'>Delete</a></td>"; echo "</tr>"; } echo "</table>";
  7. At the moment I have multiple pages with different HTML tables coded in (some have 5 columns and some 6 etc) and PHP echoing out data to populate from the database. The table in each page holds different data. It looks messy to me to code a different table for every page so I'm wondering if it's possible to create a function to do this? The function would have to print tables with different amounts of columns and echo out different data depending on what the page is along with table headers etc. How would I go about that?
  8. I have the following slice of PHP that inserts data into the database and is later called into a page. I understand I need to use the get_magic_quotes() function to stop people from inserting javascript for example into the page when the data is called back. How do I go about this? <?php $profileID = $_POST["profileID"]; $comment = $_POST["commentBox"]; $poster = $_POST["poster"]; loginDetails(); $query = "INSERT INTO comments SET id = '$profileID', comment = '$comment', poster = '$poster' "; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); echo "<h4>Comment added<h4>"; ?>
  9. Ok thanks guys, obtaining the variable from the $_GET worked like a charm I should have thought of that! Can I ask out of curiosity why you don't recommend declaring a global?
  10. I'm not entirely sure what you mean, when you say "exit" from the single quotes do you mean by using the single quotes you put round the variable? I tried the solution you posted and I'm getting nothing from that variable. I can echo out the variable just fine from outside the addComment() function though. ???
  11. I want to put a variable as the content of a hidden field. I realise that normally you would just open up a set of php tags and echo the variable in which I have done in the past, although I need the whole form in php tags as I have made the form a function in order to hide it with sessions when no body is logged in. This seems to be causing a problem as I can't get the content of the variable into the field its just echoing the actual statement in. Any help? Here's the function contained in functions.php that holds the form. <?php function addComment() { // Check if we have established an authenticated session if (isset($_SESSION["authenticatedUser"])) { echo '<form id="form1" name="form1" method="post" action="addcomment.php"> Comment: <br /> <input name="hiddenField" type="hidden" value="<?php echo $bandid ?>" /> <br /> <textarea name="commentBox" id="commentBox"></textarea> <br /> <br /> <input name="Submit" type="submit" class="button" value="Submit" /> </form>'; } else { echo '<h2>Please log in to post a comment.</h2>'; } } ?> And here's the page that pulls the function. <?php session_start(); $bandid = $_GET["bandid"]; addComment();
  12. Thanks, yes I do understand it although I could see why you may find it hard to understand due to the typos. Apologies for that I shall check before I post in the future. I did try the AND statement before you posted which did not work although I think I may have missed off the table name. The solution you suggested works fine, thanks.
  13. I have created a join between two tables that gets all of the contents from both tables into one. I now need to do this again but only list the details for a particular id that that matches the variable $bandid. I cant figure out how to go about this as I don't be able to put in ore than one WHERE statement? ??? <?php $bandid = $_GET["bandid"]; echo "<h1>Profile for: ".$bandid."</h1><br />"; include_once 'functions.php'; loginDetails(); $query = "SELECT users.id, users.bandname, users.bio, users.history, users.discography, images.path ". "FROM users, images ". "WHERE users.id = images.id";
  14. Cheers I did it with a MySQL join. It seems to be working although images are not showing properly as the image locations are all getting %3c/a added on after the file extension. Has me baffled as to why this is happening, any ideas? Full query with output <?php include_once 'functions.php'; loginDetails(); session_start(); $query = "SELECT users.id, users.bandname, images.path ". "FROM users, images ". "WHERE users.id = images.id"; //$query = "SELECT * FROM users ORDER BY id"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another echo "<table id=drtable>"; echo "<tr><td><h2>Band Image</h2></td>"; echo "<td><h2>Band Name</h2></td>"; echo "<td><h2>Band ID</h2></td></tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td><h2><a href=profile.php?bandid=".$row['id'].">","<img src=".$row['path']."</a></h2></td>"; echo "<td><h2><a href=profile.php?bandid=".$row['id'].">".$row['bandname']."</a></h2></td>"; echo "<td><h2><a href=profile.php?bandid=".$row['id'].">".$row['id']."</a></h2></td>"; echo "</tr>"; } echo "</table>"; } else { // no // print status message echo "No bands found."; } ?>
  15. I have a query below that gets its results and puts them in a table. The current results are from two fields in a db table. I am wondering if it is possible to create a second query to get results from a different db table and echo them out in the same html table as the ones already there? Many thanks. <?php include_once 'functions.php'; loginDetails(); session_start(); $query = "SELECT * FROM users ORDER BY id"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another echo "<table id=drtable>"; echo "<tr><td><h2>Band ID</h2></td>"; echo "<td><h2>Band Name</h2></td></tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td><h2><a href=profile.php?bandid=".$row['id'].">".$row['id']."</a></h2></td>"; echo "<td><h2><a href=profile.php?bandid=".$row['id'].">".$row['bandname']."</a></h2></td>"; echo "</tr>"; } echo "</table>"; } else { // no // print status message echo "No bands found."; } ?>
×
×
  • 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.