Jump to content

pjungers

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by pjungers

  1. I've managed to figure out the alternative way of doing this with this code: $result = $wpdb->get_results ("SELECT field_name, field_val FROM wp_cformsdata WHERE field_name <> 'page' OR 'Fieldset1'", OBJECT); foreach ($result as $teaminfo) { $classname = str_replace(' ', '', $teaminfo->field_name); echo "<span class=\""; echo $classname; echo "\">"; echo $teaminfo->field_val; echo "</span>"; } This doesn't provide me with as much flexibility as I had hoped, so I'd still like to know if there's a way I can echo out each field and loop it for each form submission. As you can see from the phpmyadmin screenshot from above, there's a field titled "sub_id" which increments with each form submission. I'd like to echo out each field individually and then loop it through each "sub_id". This is just one of those situations where I know what I want to do, but don't know exactly how to accomplish it. Any help is appreciated. Thank you!
  2. Here is what I receive (returns added for readability): Array ( [0] => stdClass Object ( [field_name] => Fieldset1 [field_val] => My Fieldset ) [1] => stdClass Object ( [field_name] => Team Name [field_val] => Lincoln Dominators ) [2] => stdClass Object ( [field_name] => Player Name [field_val] => Joe Player ) [3] => stdClass Object ( [field_name] => Position [field_val] => OF ) [4] => stdClass Object ( [field_name] => Number [field_val] => 3 ) [5] => stdClass Object ( [field_name] => Bats [field_val] => R ) [6] => stdClass Object ( [field_name] => Throws [field_val] => R ) [7] => stdClass Object ( [field_name] => Batting Average [field_val] => .300 ) [8] => stdClass Object ( [field_name] => High School [field_val] => Lincoln High School ) [9] => stdClass Object ( [field_name] => Graduation Year [field_val] => 2012 ) [10] => stdClass Object ( [field_name] => GPA [field_val] => 3.0 ) [11] => stdClass Object ( [field_name] => Player Name [field_val] => Jim Player ) [12] => stdClass Object ( [field_name] => Position [field_val] => 1B ) [13] => stdClass Object ( [field_name] => Number [field_val] => 5 ) [14] => stdClass Object ( [field_name] => Bats [field_val] => L ) [15] => stdClass Object ( [field_name] => Throws [field_val] => L ) [16] => stdClass Object ( [field_name] => Batting Average [field_val] => .280 ) [17] => stdClass Object ( [field_name] => High School [field_val] => Lincoln High School ) [18] => stdClass Object ( [field_name] => Graduation Year [field_val] => 2013 ) [19] => stdClass Object ( [field_name] => GPA [field_val] => 3.2 ) [20] => stdClass Object ( [field_name] => Team Name [field_val] => Xjcvnnlkxnv ) [21] => stdClass Object ( [field_name] => Player Name [field_val] => Dsffnds ) [22] => stdClass Object ( [field_name] => Position [field_val] => Kjfdssdj ) [23] => stdClass Object ( [field_name] => Number [field_val] => Sjkkjdsv ) [24] => stdClass Object ( [field_name] => Bats [field_val] => ) [25] => stdClass Object ( [field_name] => Throws [field_val] => ) [26] => stdClass Object ( [field_name] => Batting Average [field_val] => ) [27] => stdClass Object ( [field_name] => High School [field_val] => ) [28] => stdClass Object ( [field_name] => Graduation Year [field_val] => ) [29] => stdClass Object ( [field_name] => GPA [field_val] => ) [30] => stdClass Object ( [field_name] => Player Name [field_val] => ) [31] => stdClass Object ( [field_name] => Position [field_val] => ) [32] => stdClass Object ( [field_name] => Number [field_val] => ) [33] => stdClass Object ( [field_name] => Bats [field_val] => ) [34] => stdClass Object ( [field_name] => Throws [field_val] => ) [35] => stdClass Object ( [field_name] => Batting Average [field_val] => ) [36] => stdClass Object ( [field_name] => High School [field_val] => ) [37] => stdClass Object ( [field_name] => Graduation Year [field_val] => ) [38] => stdClass Object ( [field_name] => GPA [field_val] => ) )
  3. Sorry for not including any info on that as it's built into Wordpress. Here's the documentation they have on it: "Generic, mulitple row results can be pulled from the database with get_results. The function returns the entire query result as an array. Each element of this array corresponds to one row of the query result and, like get_row, can be an object, an associative array, or a numbered array." It's on this page: http://codex.wordpress.org/Class_Reference/wpdb under the SELECT Generic Results heading.
  4. I think what I'd like to do is very simple, but I just can't figure out how to accomplish the task. Fair warning -- I'm pretty new to PHP and any help is appreciated. I have a form that takes in multiple fields of data and stores it in a mysql database. I'm trying to output the data to another page on my website and I'm able to do that, but I'm really looking to output it in a way that's easily formatted using CSS. This is on a wordpress site and I'm using the following code to output my data: <?php $result = $wpdb->get_results ("SELECT field_val FROM wp_cformsdata WHERE field_name <> 'page' OR 'Fieldset1'", OBJECT); foreach ($result as $teaminfo) { echo $teaminfo->field_val . "<br/>"; } ?> Obviously, this just outputs the data with a <br> after each field value. I'd like to see if there's a way to individually echo each field, such as "echo $teaminfo->name;" or "echo $teaminfo->address;" so that I can wrap each echo within a CSS class. Alternatively, would there be a way to echo the field_val wrapped around <span class="field_name"></span> ? This would also suit my needs, but I'm not sure how to accomplish it. Also, unfortunately I don't have remote access to mysql with my hosting company, but I've included the output from myphpadmin when I run describe wp_cformsdata; : Thank you in advance for your help.
  5. That did the trick! A million thank yous to both of jcbones and AyKay47! I really appreciate the help.
  6. Just tried that and same result: $sql="SELECT distinct township from `linksurv_field_notes` WHERE `township`!='' ORDER BY `township` DESC"; $sql="SELECT distinct range from `linksurv_field_notes` WHERE `range`!='' ORDER BY `range` DESC"; I'm also seeing the same error as mentioned in my top post. The funny thing is that the first query works no problem. It's the second query that receives the error. As i understand it, once I select a township, the page is then supposed to run the 2nd query and refresh that drop down box. I don't see this behavior at all. I'd be happy to include the code that handles that if I could narrow it down. It appears that the "onClick=return submitCorner" portion is the start of this code though.
  7. Thanks for your help. The 2 SQL statements now read: $sql="SELECT distinct(township) from `linksurv_field_notes` WHERE `township`!='' ORDER BY `township` DESC"; and $sql="SELECT distinct(range) from `linksurv_field_notes` WHERE `range`!='' ORDER BY `range` DESC"; I'm still seeing the same result though on the website.
  8. Hey, this is my first time using this forum, so I apologize if I miss something and I'd like to thank you in advance for your help. I inherited some code from a different php programmer and it's not quite working right. The basics: We have a form for users to fill out where they select a Township from a drop down menu, then based on the township they choose there is a 2nd drop down populated with Range values. I can get the Township drop down to populate from the mysql database, but once you select the Township, the 2nd drop down does not populate as expected. This worked on the old web server (which I regrettably no longer have access to), but it's not working on the new web server. I hope that the problem is just a version issue where some syntax changed, but I'm not sure. Here's the function: <?php echo "<form method='post' name='tsform' id='tsform' action='".$_SERVER['PHP_SELF']."'><input type=hidden name='page' id='page' value='viewfntown'>"; echo "<table><tr VALIGN=baseline><td></td>"; echo "<td>Township: <select name='ts' id='ts'><option value=''></option>"; $sql="SELECT distinct(township) from `linksurv_field_notes` WHERE `township`!='' order by `township`;"; $result=mysql_query($sql) or die("ts sel:".mysql_error()); $NumResults=mysql_num_rows($result); for ($q=1;$q<=$NumResults;$q++) { $row=mysql_fetch_row($result); $township=$row[0]; echo "<option value='".$township."'>".$township."</option>"; } echo "</select></td>"; echo "<td>Range: <select name='rg' id='rg'><option value=''></option>"; $sql="SELECT distinct(range) from `linksurv_field_notes` WHERE `range`!='' order by `range`;"; $result=mysql_query($sql) or die("rg sel:".mysql_error()); $NumResults=mysql_num_rows($result); for ($q=1;$q<=$NumResults;$q++) { $row=mysql_fetch_row($result); $range=$row[0]; echo "<option value='".$range."'>".$range."</option>"; } echo "</select></td>"; echo "<td><button type=button onClick=\"return submitCorner('NA','NA');\">Show All Corners</button></td>"; echo "</tr>"; echo "</table>"; ?> Also, here is the error I see in Firebug: rg sel: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 'range) from `linksurv_field_notes` WHERE `range`!='' order by `range`' at line 1 I've been stumped on this for a few weeks and any help you can give is appreciated. If I left some details out, just ask. Thanks.
×
×
  • 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.