Jump to content

All Activity

This stream auto-updates     

  1. Today
  2. Yesterday
  3. The question has been answered as detailed as we can from the information provided.
  4. Um okay very helpful information but it doesnt answer my question
  5. don't execute SELECT queries inside of loops. with today's server hardware, the time it takes for php to send the sql query statement to the database server is several times longer than the time it takes the database server to execute a query. you want to limit the number of queries you execute. postgreSQL has a LIMIT n OFFSET m statement that you should use for pagination. if for some reason you are not supposed to use that for this assignment, use php's array_slice() on the $listings array to get an array of the desired ids. then use an IN() operator to get the desired rows of data using one query. btw - the header() redirect needs an exit/die statement to stop program execution. without an exit/die, all the rest of that code is still executed. since you haven't shown us what the build_listing_card() code is or what output it produces, cannot help you with what or why your view listing links should be or don't work. don't write code like this either. every pg_fetch_result() call performs a data-seek, followed by a fetch. this takes twice as long a just fetching the data, and you have a couple of dozen pg_fetch_result() statements. the query in this code will match at most one row of data. just fetch that row into a php variable, then access elements of that fetched array. this will run measurably faster and take a lot less typing to produce the code needed for the page. if your initial long list of echo statements are for debugging purposes, just use print_r() or var_dump(), surrounded by html <pre>...</pre> tags to format the output. if this output is instead a desired part of the page output, don't spend your time typing out line after line of code for each possible field/column. use a loop and let php do the work for you.
  6. Do not use the session to pass data between specific pages. Use the query string and $_GET. The session may look appealing but it has a number of drawbacks, such as being unable to view the same page with two different sets of data, and users being unable to copy or share URLs to a page.
  7. What does your updated code, where you tried using glob(), look like? The only line you've shown for that is the following: $directoryList = glob($directory); If that's the code you're referring to, we'll need to at least see what $directory is set to.
  8. Here's a simplified example $uid = 2; $res = $bdd->prepare("SELECT f.id , f.name , u.file_id FROM files f LEFT JOIN user_files u ON f.id = u.file_id AND u.user_id = ? ORDER BY f.id "); $res->execute([$uid]); $tdata = ''; foreach ($res as $row) { $disabled = $row['file_id'] ? 'disabled' : ''; $tdata .= "<tr> <td>{$row['id']}</td> <td>{$row['name']}</td> <td><button $disabled>Download</button></td> </tr> "; } ?> <html> <head> <title>Example</title> </head> <body> <table> <?=$tdata?> </table> </body> </html>
  9. Have you tried recreating test files in your database using images as input? SHOW CREATE TABLE files; SHOW CREATE TABLE user_files; Use a single query on both tables and use a LEFT JOIN. That way you know which are present in both tables. Disable the button where the file is in both.
  10. Only select check boxes (and radio buttons) are sent in the form data so you need you check if they are present using isset(). Example <?php for ($i=1; $i<=5; $i++) { if (isset($_GET['mycb'][$i])) { echo "Check box $i selected<br>" ; } } ?> <html> <head> <title>Example</title> </head> <body> <hr> <form> Check box 1 : <input type="checkbox" name="mycb[1]" value="1"><br> Check box 2 : <input type="checkbox" name="mycb[2]" value="2"><br> Check box 3 : <input type="checkbox" name="mycb[3]" value="3"><br> Check box 4 : <input type="checkbox" name="mycb[4]" value="4"><br> Check box 5 : <input type="checkbox" name="mycb[5]" value="5"><br><br> <input type="submit" name="btnSub" value="Submit"> </form> </body> </html>
  11. All query : $row $rocket = $bdd->query('SELECT * FROM files'); $row2 $rocket2 = $bdd->prepare('SELECT * FROM user_files WHERE user_id = ?'); $rocket2->execute(array($uid)); $row2 = $rocket2->fetch(); Files table structure user_files table structure
  12. I'm facing trouble on check box when register form is submitted without check the check button, but when the button is checked the error disappear . can you give me idea why and how to solve this issue. I saw many sites with such kind of button on registration form please any one who can solve this.
  13. What is the query to get $row? What is the query to get $row2? (If you used "SELECT * ' the provide the table structures too)
  14. Hi, I am a newbie in PHP (about week and a half). I'm writing a website for myself right now. I've got a problem that I cannot solve. The website is about buying files with website custom balance. What I want to do is disable buy button if user bought this file b4. The is a table user_files that stores user id and file id. And another table that stores files data, ID name who uploaded date time ect.... What I'm trying to do, is disabling buy button if the user has already the file. This is what I've done : while ($row = $rocket->fetch()) { ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['name']; ?></td> <td><?php echo $row['uploader']; ?></td> <td><?php echo $row['uploadtime']; ?></td> <td><button <?php // Echo "disabled" if $row['id'] id is present in row2['file_id'] <<<<<<< Need to do this in a while. ?> ><a href="download.php?id=<?php echo $row['id']; ?>"></a><?php echo $row['price'] . "D$" ?></button></td> </tr> <?php } ?> What I can't do is check if the file id ($row['id']) is present in ($row2['file_id']), if yes echo "disabled";
  15. As above, the script came with a file "unknown.php" which is just empty, I can't see how the code would ever use the file as I can't see it referenced in the code anywhere? What I did was modify "countries.php" by adding this code :- "UNKNOWN" => array("Undeclared","an undeclared location"), It all works as it should, if the IP is from an unknown location the text I added to countries.php is displayed. It just seems odd the original author had "unknown.php"? Thanks
  16. You are fetching $_GET['listing_id'] from the URL, so you have to provide that info at least in a link.
  17. Hi, So I am currently making a real estate site for my class at school but I am having a tiny issue with the listing display page. So what I want to do is show a bunch of listing that the agent owns on their dashboard which I have already done. Now I have two links one to update the listing and one to view the listing. Now what I am trying to do is when the view listing link is clicked it will take the user to the listing-display page and then I want it to display all the information for the listing that the link was clicked under. But i cannot for the life of me figure out how to do that! This is currently the code for the dashboard where you only view the listing headline <?php // If the session was never set with a user id $output = ''; $conn = db_connect(); if($_SESSION['userType'] != AGENT) { $_SESSION['RedirectError'] = "You were not logged in as an Agent<br/>"; header("Location:login.php"); } if (isset($_GET["page"])) { $page = $_GET["page"]; $index = ($page -1) * IMAGE_LIMIT; } else { $page=1; $index = 0; } ?> <!-- start of main page content --> <div class="container" style="margin-top: 2em;"> <h2>Dashboard</h2> <p>Welcome back <?php echo $_SESSION['userId']; ?> you last logged in on <?php echo $_SESSION['last_access']; ?></p> <h4>Your Listings</h4> <?php $sql = "SELECT listing_id FROM listings WHERE user_id = '".$_SESSION['userId']."' AND status = 'o' ORDER BY listing_id"; $result = pg_query($conn, $sql); $listings = pg_fetch_all($result); for($index; $index < pg_num_rows($result); $index++) { $sql = "SELECT * FROM listings WHERE listing_id = '".$listings[$index]['listing_id']."'"; $listing_result = pg_query($conn, $sql); $arrayRow = pg_fetch_assoc($listing_result); echo (build_listing_card($arrayRow)); if($index !=0 && ($index +1) % IMAGE_LIMIT ==0){ break; } } ?> </div> <br/> <?php $total_pages = ceil(count($listings) / IMAGE_LIMIT); $pageLink = "<div class='pagination'>"; for ($i=1; $i<=$total_pages; $i++) { if($i == $page) { $pageLink .= "<a class='active' href='dashboard.php?page=".$i."'>".$i."</a>"; } else { $pageLink .= "<a href='dashboard.php?page=".$i."'>".$i."</a>"; } }; ?> </div> <br/> and this is the code for the listing-display page where I want all the listing information to be displayed <?php if (isset($_GET['listing_id'])) { $_SESSION['listing_id'] = $_GET['listing_id']; } else { $_SESSION['listing_id'] = 0; echo "ERROR: listing information was not find"; } $sql = 'SELECT * FROM listings WHERE listing_id = ' . $_SESSION['listing_id']; echo "<BR>".$sql; $result = pg_query(db_connect(), $sql); $records = pg_num_rows($result); echo "<BR>".pg_fetch_result($result, 0, "listing_id"); echo "<BR>".pg_fetch_result($result, 0, "user_id"); echo "<BR>".pg_fetch_result($result, 0, "status"); echo "<BR>".pg_fetch_result($result, 0, "price"); echo "<BR>".pg_fetch_result($result, 0, "headline"); echo "<BR>".pg_fetch_result($result, 0, "description"); echo "<BR>".pg_fetch_result($result, 0, "postal_code"); echo "<BR>".pg_fetch_result($result, 0, "images"); echo "<BR>".pg_fetch_result($result, 0, "city"); echo "<BR>".pg_fetch_result($result, 0, "property_options"); echo "<BR>".pg_fetch_result($result, 0, "bedrooms"); echo "<BR>".pg_fetch_result($result, 0, "bathrooms"); echo "<BR>".pg_fetch_result($result, 0, "garage"); echo "<BR>".pg_fetch_result($result, 0, "purchase_type"); echo "<BR>".pg_fetch_result($result, 0, "property_type"); echo "<BR>".pg_fetch_result($result, 0, "finished_basement"); echo "<BR>".pg_fetch_result($result, 0, "open_house"); echo "<BR>".pg_fetch_result($result, 0, "schools"); ?> <h1> Listing Display </h1> <hr/> <table style="width:50%" border="1px solid black"> <tr> <th>Listing Image</th> <th>Listing Description</th> </tr> <tr> <th rowspan="2"> <img src="" alt="Oshawa House" width="300px" height="200px"/> </th> <td align="left" valign="top"> <h3><?php echo pg_fetch_result($result, 0, "headline") ?></h3> <ul> <li>Open house?: <?php echo get_property('open_house', pg_fetch_result($result, 0, "open_house"))?> </li> <li>Finished Basement?: <?php echo get_property('finished_basement', pg_fetch_result($result, 0, "finished_basement"))?></li> <li><?php echo get_property('purchase_type', pg_fetch_result($result, 0, "purchase_type"))?></li> <li>Garage Type: <?php echo get_property('garage_type', pg_fetch_result($result, 0, "garage"))?></li> <li>Near school?: <?php echo get_property('schools', pg_fetch_result($result, 0, "schools"))?></li> <li>Status: <?php echo get_property('listing_status', strtolower(pg_fetch_result($result, 0, "status"))) ?></li> <li>Washrooms: <?php echo get_property('washrooms',pg_fetch_result($result, 0, "bathrooms")) ?></li> <li>Bedrooms: <?php echo get_property('bedrooms',pg_fetch_result($result, 0, "bedrooms")) ?></li> <li>Description: <?php echo pg_fetch_result($result, 0, "description") ?></li> </ul> </td> </tr> <tr> <td align="left" valign="top"><ul> <li>Location: <?php echo get_property('cities',pg_fetch_result($result, 0, "city")) ?></li> <li>Postal Code: <?php echo pg_fetch_result($result, 0, "postal_code") ?></li> <li>Price: <?php echo pg_fetch_result($result, 0, "price") ?></li> </ul> </td> </tr> </table> <form action="listing-matches.php"> <p> <input type="submit" name="submit" value="Back"/></p> </form>
  18. I'm sorry but as a policy we do not delete accounts or posts, with obvious exceptions like for spammers, and when required to by law (ie, for EU residents). If you're concerned about personal information, all we have is what you've provided - and it appears you haven't provided anything. We don't mind if you just, you know, not use your account.
  19. I don't use this account anymore and would like it to be removed. Thank you.
  20. One way to help decide if you should bother with DI is to ask whether anyone outside of your code has an real reason to create said object. As an example, I has a project where there was a service to start background jobs. The method startJob() would return a Job object that detailed things about the newly created job and have a couple methods to manage it. There's really no reason for anyone other than that method to try and construct that class so there's not much point in going though DI for it. Instead it just does return new Job($details);
  21. Last week
  22. If it toggles every hour then the time-based value does not require a cron job. The value is available anytime you need it SELECT HOUR(NOW()) MOD 2 as value
  23. I'm partial to x = 1 - x. Are you sure you need a cronjob for this? Very many "I need a cronjob to do X" problems can be resolved in a way that doesn't need a cronjob...
  24. This command works perfectly !! Thank you very much for your help
  25. UPDATE tableZ SET x = (x = 0) WHERE id = 1
  26. A ok sir thank you very much.. 1 more quick question i would have if you may please.. i am pretty bad at this sorry :)) So lets say i have the following table Z: ID value 1 0 2 0 Now.. i tried in my cronjob i did "UPDATE Z SET value=1" i did this set a cronjob for the first 30 minutes of an hour .. then the next 30 minutes i can just add another cronjob that sets the value 0.. ( i found this to be easier i think that using a toggle because i am noob ) So everything is fine.. the above command updates my values.. but i want only for ID 1 to do the value change not all.. how can i do that please ? What do i need to change or add in the above command to only update the ID 1 ? I tried with a WHERE but i dont think i placed it right it didnt work.. Thanks sir
  27. A couple of methods spring to mind 1 ) toggle the value between 0 and 1 ... UPDATE tableZ SET x = CASE WHEN x = 1 THEN 0 ELSE 1 END; or UPDATE tableZ SET x = (x = 0); 2 ) set it based on the time UPDATE tableZ SET x = HOUR(NOW()) MOD 2; Of course the queries may need a WHERE clause unless you want to apply the change to every record in tableZ.
  1. Load more activity
  • Member Statistics

    • Total Members
    • Most Online

    Newest Member
  • Forum Statistics

    • Total Topics
    • Total Posts
  • 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.