Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. @doddsey_65 There are several issues with the code in the last post. I'm pretty sure there is only one record in the first row and two in the others is because of the improperly formatted table. If you look at the code view for the page, I'm sure you'll see that you're missing the first open row tag. And the column after the username in every row was never closed. The reason why you only get two records per row is because your incrementing the column counter ($i) in the beginning instead of the end. You're while loop should look closer to this: $i=0; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { //IF FIRST TIME, OPEN A NEW ROW if($i==0) { echo '<tr>'; } //IF WE HAVE ALREADY PRINTED 3 RECORDS, CLOSE THE OLD ROW AND OPEN A NEW ONE if($i==2) { echo '</tr><tr>'; $i=0; //reset counter } //DISPLAY CURRENT THUMBNAIL echo '<td><center><img src=' . $row['thumbpath'] . ' height="100" width="125" hspace="10" style="border: 1px solid #fff;"></center></td>'; echo '<td>' . $row['name'] . '<br>' . $row['username'] . '</td>'; //INCREMENT COUNTER $i++; } Note that you still need to write some code after the while loop which will close any open rows.
  2. I would imagine that would give more than the two records the OP was looking for. Note that I agree that UNION is overkill. Using two seperate queries would probably be the way to go. Then process the results afterwards.
  3. OK, I figured out a solution: (SELECT id, org, type, CONCAT('0') AS isOther FROM stakeholders) UNION (SELECT id, orgOther, orgOtherType, CONCAT('1') FROM otherStakeholders) ORDER BY type, org If you know of a better solutions, I'm open to suggestions.
  4. Did you try the UNION example? It should give you both records. Also, is there a reason why you need it to be one statment? You could just process both statements and work with the results afterwards.
  5. I'm using UNION to merge two resultsets. Everything works, but I trying to figure out how to add a flag to the resultset. Basically I have a table for pre-defined stakeholders and a table for other stakeholders. Since I'll be using the id from both tables and it may overlap, I would like to create a flag to indicate if its an other stakeholder or not. Here is my query so far: (SELECT id, org, type FROM stakeholders) UNION (SELECT id, orgOther, orgOtherType FROM otherStakeholders) ORDER BY type, org Here is the "stakeholders" table: idorgtype 1s1National 2s2State/Local 3s3State/Local 4s4National Here is the "otherStakeholders" table: idorgOtherorgOtherType 1other_s1National 2other_s2State/Local Note that the otherStakeholders table has been simplified...there is a reason why it's stored in a seperate table. Also, I'm using MySQL 5.0 if it matters.
  6. Have you tried using UNION? (SELECT title, abstract, body FROM Articles WHERE category_id = 1 AND id = 3015) UNION (SELECT title, abstract, body FROM Articles WHERE category_id = 1 AND id > 3015 ORDER BY order_num ASC LIMIT 1)
  7. Thanks for the excellent tips. I'm not sure why I didn't think about using strtolower(). I'll most likely switch to that.
  8. I'm using preg_match to compare new user input to an existing database entry. What I have works for the most part but I ran into an issue when that user input contains special characters like parenthesis. Is there a function available to escape these characters? Or maybe there's a way to tell PHP to treat what's inside a variable as text only? For example, here is a simplified version of what I was using to test a phone number: if(preg_match("/^$newPhoneNum$/i", $databasePhoneNum)) { //DO NOTHING } else { //CREATE A BUTTON THAT UPDATES THE DATABASE } The above code doesn't work if $newPhoneNum is equal to "(888)888-8888" due to the parenthesis. So I modified the code to be: $newPhoneNum = preg_replace("/[^a-zA-Z0-9]/", '', $newPhoneNum); $databasePhoneNum = preg_replace("/[^a-zA-Z0-9]/", '', $databasePhoneNum); if(preg_match("/^$newPhoneNum$/i", $databasePhoneNum)) { //DO NOTHING } else { //CREATE A BUTTON THAT UPDATES THE DATABASE } The new code not only solved the issue with parenthesis, but it also matches phone numbers like "888-888-8888", "(888) 888-8888", etc. But I still could have problems with the other fields (name, address, etc.). Is there another solution that I'm missing, or do I need to keep using things like preg_replace to remove troublesome characters? :-\
  9. In your form tag, don't you need the action attribute: [code] <form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>"> ... [/code]
  10. [!--quoteo(post=376051:date=May 22 2006, 10:12 AM:name=glenelkins)--][div class=\'quotetop\']QUOTE(glenelkins @ May 22 2006, 10:12 AM) [snapback]376051[/snapback][/div][div class=\'quotemain\'][!--quotec--] why dont you try something like this: [code] $name[0] = "Bob"; $org[0] = "Builders Ltd"; $title[0] = "Mr"; $email[0] = "bob@buildersltd.com"; $phone[0] = "01578968345"; for ($i=0; $i < $number_of_inserts; $i++) { mysql_query ("INSERT INTO authors VALUES ('$name[$i]','$org[$i]','$title[$i]','$email[$i]','$phone[$i]'"); $id_list[$i] = mysql_insert_id(); } foreach ($id_list as $id) { echo $id . "<br>"; } [/quote] I already have something like that, but I would like to get away from all the for loops. I have one loop to read the info from the online form, another to store the info to the database, and another one to strip the slashes from the input and print the info to the screen.
  11. Is there any way to get multiple IDs when performing an INSERT statement which inserts more than one row? Our INSERT statement looks something like: [code] INSERT INTO authors (name, org, title, email, phone) VALUES ('name1', 'org1', 'title1', 'email1', 'phone1'), ('name2', 'org2', 'title2', 'email2', 'phone2'); [/code] I normally use: [code] mysql_insert_id() [/code] ...to get the insert id, but this only gives me the ID for the first insert. Thanks
  12. So where did you find this Application Data directory? I did a search of my C drive and only found two CodeColoring.xml files. Both under C:\Program Files\Macromedia\Dreamweaver MX 2004\ I changed both files as "davidennis99" instructed and no luck. With the exception of: "To change the colors: edit->preferences->Color COding->HTML->PHP NOT edit->preferences->Color COding->PHP (this will just change the colors in .php-ish named files, not html files.."
×
×
  • 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.