Jump to content

joel24

Members
  • Posts

    760
  • Joined

  • Last visited

Everything posted by joel24

  1. your loop is setting the value of one array index "$data['products']['preview_image']" if you want to have $data['products']['preview_image'][x] WHERE x is automatically incremented 1,2,3,4,5,6 etc you need to do //modify the products array foreach($data['raw_products'] as $data['products']) { //set the preview image row $data['products']['preview_image'][] = anchor('admin/list_products/#', "View IMG", array("onHover" => "admin.previewIMG('".$data['products']['preview_image']."')", "class" => "noLink")); //set the body image row $data['products']['body_image'][] = anchor('admin/list_products/#', "View IMG", array("onHover" => "admin.bodyIMG('".$data['products']['body_image']."')", "class" => "noLink")); } or if you're looing to set the first index from the foreach key, //modify the products array foreach($data['raw_products'] as $current) { //set the preview image row $data[$current]['preview_image'] = anchor('admin/list_products/#', "View IMG", array("onHover" => "admin.previewIMG('".$data['products']['preview_image']."')", "class" => "noLink")); //set the body image row $data[$current]['body_image'] = anchor('admin/list_products/#', "View IMG", array("onHover" => "admin.bodyIMG('".$data['products']['body_image']."')", "class" => "noLink")); } and if you want to edit an existing array outside of the foreach's scope, look here and so something like foreach ($data['raw_products'] as &$current) { //whatever code her will write to the $data['raw_products'] array $current = 'whatever'; }
  2. to have a JOIN you need to associate the two tables through a primary key and a foreign key... google 'joining mysql tables' what are the table columns in both the `site` and `background` tables? what are the primary keys etc a join would be like so... say you have two tables, user & company. user has columns userID, username, password, email, companyID AND company has columns companyID, companyName, backgroundImage You can see in the user table, companyID is a foreign key which links the user to a company your join would be like SELECT u.*,c.* FROM user u JOIN company c ON u.companyID = c.companyID that will return the user's name, pwd, email AND the companyName, background image etc and as for the second question, yes you can do this. You will need to either make the red image a link/anchor echo "<a href='yourPage.php?image={$row['image']}><img src='theImageFromDatabase.jpg'/></a>" Then have a bit in the page like if (isset($_GET['image'])) { $background_image=$_GET['image']; } you can use jquery/ajax to load this a bit nicer, though for now just try the aforementioned
  3. you should try and use one query with a join if possible?? if you have a look in the generated pages source code, I dare say only one iteration of your while loop is executing? I'm not 100% sure on this, but to execute the code the way you've set it out, you would have to call the 2nd query for each iteration of the while loop... bad for performance though, use a join if you can <?php $sqlCommand = "SELECT image FROM background"; $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); while ($row = mysqli_fetch_array($query)) { $sqlCommand2 = "SELECT backgroundimage FROM site"; $query2 = mysqli_query($myConnection, $sqlCommand2) or die (mysqli_error()); while ($row2 = mysqli_fetch_array($query2)) { if($row['image'] == $row2['backgroundimage']){ echo '<img src="site_background/'.$row['image'].'" width="75px" height="75px" style="border:2px solid red;" /><br />'; } if($row['image'] != $row2['backgroundimage']){ echo '<img src="site_background/'.$row['image'].'" width="75px" height="75px" style="border:2px solid black;" /><br />'; } } } mysqli_free_result($query); mysqli_free_result($query2); ?>
  4. Couldn't agree more! Nicely said
  5. put this line at the top of the PHP and post what it echoes print_r($_POST);
  6. you don't need to open and close the <?php ?> tags so often, you only need to open at the start and close after the end of the PHP code. The syntax error you're getting would be because you are missing a set of closing brackets for the while loop <?php if (db_num_rows($queryGetNews) > 0) { while ($objRow= db_fetch_object($queryGetArticle)) { //open while loop $intRaceID = intval($objRow->intID); $txtUpdate = strip_tags(stripslashes($objRow->txtUpdate)); $dtEntered = stripslashes($objRow->dtEntered); echo $txtUpdate; echo date("g:i A", strtotime($dtEntered)); } //close while loop } else { //close IF and add else statement //throw error message echo "error has occured or no rows returned<br/>".mysql_error(); }?>
  7. for starters you're posting the form variables and trying to retrieve them with $_GET if(isset($_GET['submit'])) { //this line should be if(isset($_POST['Submit'])) {
  8. did you put anything in the else part of the if statement? if (db_num_rows($queryGetNews) > 0) { //while loop } else { //throw error message echo "error has occured or no rows returned<br/>".mysql_error(); }
  9. have you tested your code to see if it works?
  10. to show all errors, set error_reporting to E_ALL error_reporting(E_ALL); for the lines that are returning the error, what is your code? for using $_GET and $_POST variables you should have an if (isset($_GET['variable'])) { //do whatever... }
  11. if you had lots of tables then you would be incorporating a lot of joins or numerous commands, which would in effect be the same if not more power intensive as having one tables with many rows. Keep your tables focused to their task, don't go trying to slim down the DB by making one table keep several tasks data and mysql is developed to handle huge databases with millions of rows
  12. haven't heard of any, though I'm sure google will source one for you.
  13. I have not idea why it wouldn't be saving, so many possible scenarios. Try writing your scripts on your local computer, if you don't want to buy a program you can use free programs like Notepad++, then upload those files to your server.
  14. I would store those selected companies in the session then use a NOT IN clause to ensure they weren't returned in the SELECT form element i.e. $array = $_SESSION['CompanyAdded']; $companiesSelected = "('".implode("',",$array)."')"; $result = mysql_query("SELECT CompanyName from customers WHERE CompanyName NOT IN $companiesSelected");
  15. what is your 'php panel'?? What do you mean it never saves? You're trying to save it on your hard drive or this is some online application that you're entering this into?
  16. You should have one database, and several tables, One for the quiz names, settings, etc One for quiz questions (linked to the quiz name with a quizID and identified with a questionID) One for users (login, password, name, email etc) One for usersQuestions which will list the attempted questions. This table would hold the questionID and the userID and the mark for that question. Primary keys questionID and userID, then use a INSERT ON DUPLICATE UPDATE query and if the user attempts to redo the question, this will update the row with the new mark rather than creating a new one, otherwise it will just insert a new row (for first attempts)
  17. you can send the variables in the URL and have a link/image for the user to click. Then retrieve with $_GET i.e. page1 $sql = @mysql_query("SELECT userID, name FROM users WHERE company='4'"); while ($row = mysql_fetch_array($query)) { echo "<p><b>{$row['name']}</b><br/> echo "<a href='editPage.php?user={$row['user']}'>Edit User</a>"; echo '</p>'; } then on editPage.php $userID = mysql_real_escape_string($_GET['user']); $sql = @mysql_query("SELECT //do whatever you'll have to ensure the logged in user is allowed to edit/modify the selected user on the editPage.php, by using session variables etc
  18. set it in the session variables, //ensure this line is at the top of each page session_start(); //now you can set session variables $_SESSION['myVariable']=$_POST['name']; //now on the 2nd page make sure you have session_start(); up the top and you'll be able to call $_SESSION['myVariable'];
  19. something along these lines SELECT b.model, SUM(b.quantity) - SUM(s.quantity) AS currentQuantity FROM sell s JOIN buy b ON s.model=b.model GROUP BY b.model
  20. hit the nail on the head! it is for a company's pay-roll I'll have a play around with it and see what I can do
  21. I would definitely go with the 2nd option (an association table). That way you would be able to pull the applicable rows with one single mysql query (job board table JOIN keyword table) rather than querying the job board table, pulling all rows and then reading keywords in PHP.
  22. Just wondering whether to set a 'deleted' column to either 1 or 0 (true/false) or allow users to delete the row... some other tables rely on rows in other tables as foreign keys, so deleting them would disrupt this though how would keeping the rows impact on performance...? throw me your ideas!
  23. won't let me modify to fix up the URL, fixed mysql week URL
  24. I would use an array from the start i.e. $user = 'user'.$row2['author']; $userArray = array(); if (!isset($$user)){ $result = $connector->query('SELECT * FROM users WHERE ID = '.$row2['author']); $userArray[$user] = $connector->fetchArray($result); } echo '<a href="user.php?user='.$userArray[$user]['ID'].'">'.$user.'</a></p>'; play around with that, otherwise do print_r($$user); to ensure the variable variable array is setup as you wish.
×
×
  • 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.