
Jim R
Members-
Posts
1,006 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Jim R
-
It's not the connection, selected database or table/column. The only time the error arrives is when I add the WHERE condition.
-
Are we not trying to determine what is causing it? Bad syntax in the query or gathering of results.
-
@objnoob, I got the same error using your second line. Maybe more information will help: In WordPress, I'm trying to match an Tag archive to the first and last name of the player in a separate data table, where I have profile type information. I had a small plugin I wrote that copied over their tag_id to the separate data table, but a WordPress upgrade broke it. As I was trying to fix it, I figured I could just use Tag Archive name and match it. So it used to work and work well.
-
I'm trying match data from two different tables. The single_tag_title is producing the results I want via the echo, but I can't seem to get the syntax down in the query. $slug = single_tag_title(); echo $slug; $query = 'SELECT * FROM a_playerRank WHERE CONCAT(nameFirst," ",nameLast) = "$slug"'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { I get the following error:
-
I tried to attach a CSV file earlier, but it wouldn't let me.
-
It's printing 0 for the players with NULL in the "rankPos" column, even though in grouping 1 and 0 I don't have code for it to print rankPos.
-
Can I have a Select *? I added the other columns I needed. It's printing 0 for the players with NULL in the "rankPos" column, even though in grouping 1 and 0 I don't have code for it to print rankPos.
-
Do you mean from the database itself? I tried to attach a CSV file.
-
Any help with this? I've looked up "conditional order by", but I'm not sure it applies to what I'm trying to do.
-
I tried that first actually. It didn't work. I looked around and found something on Stackflow saying that wasn't used anymore. In testing the rowCount, I realized I had '$result' not '$results' but never went back to mysql_num_rows to test it again. Thanks.
-
I have a list of players who have committed to play basketball at a college. Above that list, I'd like to print the total number of kids committed so far. I don't think counting inside the Loop will help me print what I want, so I looked into printing the number of returned rows. I came across rowCount, but I'm not able to get the syntax down or even understand how to use it. I get the follow error: Fatal error: Call to a member function rowCount() on a non-object in/home4/####/public_html/resources/commitments/commitment2014.phpon line 8 $query = 'SELECT * FROM a_playerRank WHERE YEAR="2014" AND commit="1" AND state="IN" ORDER BY nameLast'; $results = mysql_query($query); $count = $results->rowCount(); echo '<div class="commit_list">'; echo 'There are '.$count.' kids committed.'; Seems easy enough, but I'm clearly missing something or misusing it altogether. Thank you.
-
What you suggested for the query worked. It took some trial and error to get it print out the way I wanted it. The troublesome part continued to be that 'pr.commit' applied to players who weren't committed to the school featured in the current Page. http://hoosierhoopsreport.com/pu Here is the final code: // Gets Page title $page = get_the_title(); //echo $page; if(!$con = mysql_connect("localhost","jwrbloom_","redcoach")) { die("Could not connect to database: ".mysql_error()); } mysql_select_db("jwrbloom_hhrplayers", $con); $sql ="SELECT * FROM a_playerRank AS pr JOIN playerCollege AS pc ON pr.id = pc.id_player WHERE pr.year = '2014' AND pc.colleges = '". $page ."' ORDER BY (pr.commit='1' AND (pr.college = pc.colleges)) DESC, pc.offer desc, pr.nameLast"; $results = mysql_query($sql); $position = array ( '1' =>'PG', '2' =>'SG', '3' =>'SF', '4' =>'PF', '5' =>'C' ); $currentCollege = false; $currentOffer = false; echo '<div class="recruitWrap">'; while ($line = mysql_fetch_assoc($results)) { $collegeCommit = $line['college']; if($line['college'] != $page) { $line['college'] = ''; } if($line['college'] == $page && $line['commit'] == '1') { if ($currentCollege !=$line['commit']) { $currentCollege = $line['commit']; echo '<div class="recruitHeader">Committed</div>'; } } elseif ($currentOffer !=$line['offer']) { $currentOffer = $line['offer']; if($line['offer'] == '1') { echo '<div class="recruitHeader">Offered</div>'; } elseif ($line['offer'] != '1') { echo '<div class="recruitHeader">Also recruiting</div>'; } } //if((ISSET ($line['college']) && $line['college'] == $line['colleges']) || !ISSET($line['college'])) echo '<div class="recruitRow"> <div class="recruit">' . $line['nameFirst'] . ' ' . $line['nameLast'] . '</div>'; echo '<div class="recruit recruitHeight">' . $line['feet'] . '\'' . $line['inches'] . '"</div>'; echo '<div class="recruit recruitPosition">' . $position[$line['position']] . '</div>'; echo '<div class="recruit recruitSchool">'; if ($line['city'] !='') { echo $line['city'] . ' (' . $line['school'] . ')'; } else { echo $line['school'] . ' HS'; } echo '</div>'; // city school echo '<div class="clear"></div>'; echo '</div>'; if($line['commit'] == '1' && $line['college'] != $page) { echo '<div class="otherCollege">Committed to '. $collegeCommit .'</div>'; } } echo '<div class="clear"></div>'; echo '</div>'; // recruit wrap ?> Thanks for your time on this issue. I always get great help here, as it seems anything I try comes with a learning curve. At least the issues get more complicated, and I'm pretty good at porting anything I've done in the past over to new projects.
-
I can easily change the 'y' to '1'. Would you recommend I make it so NULL isn't possible? So it's 1 or 0?
-
I tried your query, but it didn't change the order. (I took out the headers and just had it print the list.) Mathias should be on top. He is pr.commit = 'y' pr.college = 'Purdue' / pc.colleges = 'Purdue' pc.offer = 'y' McIntosh should be at the bottom pr.commit = 'y' pr.college ='Indiana State' / pc.colleges = 'Purdue' pc.offer = 'y' The other guys on this list are pr.commit = '' pr.college = '' / pc.colleges = 'Purdue' pc.offer = 'y' Dakota Mathias 6’4″ SG Elida HS Bryant McIntosh 6’4″ PG Greensburg HS Committed to Indiana State Alec Brennan 6’9″ PF Milton (Academy) Michael Chandler 6’10″ C Niceville (NW Florida State (JC)) Jabari Craig 6’10″ C Waynesboro (Fishburne Military) Vince Edwards 6’6″ SF Franklin (Middletown) Isaac Haas 7’2″ C Piedmont (Hokes Bluff) Ronnie Harrell 6’6″ SF Denver (East) JP Macura 6’5″ SG Lakeville (North)
-
I looked for those types of conditions in Order By and came up with Case statements. Before I dig too deep, if what I'm ultimately interested in the top group is pr.college = pc.colleges. At that point pr.commit would be implied, so I wouldn't have to sort by pr.commit. Do you think just using (pr.college = pc.colleges) as the condition would work? Right after the SELECT * statement, what does the condition do for me there? I understand what it does in the Order By statement. Thanks for your time.
-
Disregard the previous post. :-) What about a Case statement in the Order By?
-
If I use $line = mysql_fetch_assoc($results) instead of... while ($line = mysql_fetch_assoc($results)) { Can I use multiple WHILEs to parse my data?
-
I can understand why it would not have enough information More detail about my tables and columns. a_playerRank is my main table, noted as pr playerCollege is a table used to link a player's ID to each school that may be involved with him, noted as pc pr.commit tells us whether or not the player is committed, while pr.college tells which college it is if pr.commit = 'y'. pc.colleges is a school recruiting a player (each kid's id might have 2-12 rows, each with a different school). If a school offers a scholarship, pc.offer = 'y'. It's the ORDER of the results I'm looking to alter. A list of players recruited by the same school. In this case $page = Purdue I'm trying to have three groups within that list Players committed to that school (pr.commit = 'y' pc.offer = 'y' pr.college = $page pc.colleges = $page) Players offered a scholarship by that school (pc.offer = 'y') Players the schools are still evaluating (pc.offer = 'y') That part is easy. Where it gets complicated is if a player commits to another school, I would like to note that. So among players recruited by $page (Purdue), my ORDER BY puts players commit = 'y' first, even though they may be committed to another school. The second two groups will have a mix of players who are or aren't committed to any school, but definitely not committed to $page (Purdue in this instance). (I'll be applying this code on about 20-30 school pages down the road.) Right now, among the list on the page I linked above, two players out of ten are committed. One is committed to $page (Purdue), the other is not. I want the one who isn't committed to $page to show up in one of the other two groups (with the note that he is committed to another school). Can I use a WHILE? WHILE pr.college = $page { } There needs to be a while...else.
-
Could I utilize Case in the Order By part of my query? Order By "commit" where "college" (the college committed to) != "colleges" (the college recruiting him)
-
Is there a way to take my results assigning value to a variable so I can change where it shows up on my list without altering the database? I can make it not echo the instance I noted above, but I can't change where it shows up. The page title controls one of the query variables, in this case Purdue University. Any player in the database recruited by Purdue will eventually show up on that list. However, most of them will commit to play for another school. I want to be able to reflect that a player has been recruited by one school yet committed to another.
-
Really it would just be an IF. Here is a link to my page: http://hoosierhoopsreport.com/pu I want the instance of... Bryant McIntosh 6'4" Greensburg Committed to Indiana State ...in the Offered group. This will allow me to reflect where a player decided to attend who was offered a scholarship by the college in the current view. The trigger is the column "commit". When pr.college != pc.colleges (which matches the WordPress page title / $page), it basically says that player did not commit to the college in the current view. They committed somewhere else. Somehow when Bryant McIntosh' instance comes through the query, pr.commit needs to not equal "y" // Gets Page title $page = get_the_title(); //echo $page; $sql ="SELECT * FROM a_playerRank AS pr, playerCollege AS pc WHERE pr.id = pc.id_player AND pr.year = '2014' AND pc.colleges = '". $page ."' ORDER BY pr.commit desc,pc.offer desc,pr.nameLast "; $results = mysql_query($sql); $position = array ( '1' =>'PG', '2' =>'SG', '3' =>'SF', '4' =>'PF', '5' =>'C' ); $currentCommit = false; $currentOffer = false; echo '<div class="recruitWrap">'; while ($line = mysql_fetch_assoc($results)) { if ($currentCommit != $line['commit']) { $currentCommit = $line['commit']; if ($line['commit'] == 'y') { echo '<div class="recruitHeader">Committed</div>'; } else { echo '<div class="recruitHeader">Offered</div>'; } } if ($currentOffer !=$line['offer']) { $currentOffer = $line['offer']; if ($line['offer'] == 'y') { } else { echo '<div class="recruitHeader">Also recruiting</div>'; } } //if((ISSET ($line['college']) && $line['college'] == $line['colleges']) || !ISSET($line['college'])) echo '<div class="recruitRow"> <div class="recruit">' . $line['nameFirst'] . ' ' . $line['nameLast'] . '</div>'; echo '<div class="recruit recruitHeight">' . $line['feet'] . '\'' . $line['inches'] . '"</div>'; echo '<div class="recruit recruitPosition">' . $position[$line['position']] . '</div>'; echo '<div class="recruit recruitSchool">'; if ($line['city'] !='') { echo $line['city'] . ' (' . $line['school'] . ')'; } else { echo $line['school'] . ' HS'; } echo '</div>'; // city school echo '<div class="clear"></div>'; echo '</div>'; if($line['college'] != $page) { echo '<div>Committed to '. $line['college'] .'</div>'; } } echo '<div class="clear"></div>'; echo '</div>'; // recruit wrap
-
Yes, that makes perfect sense, and in having mismatched variables, it 'worked'. It was weird though, I went awhile with no spam after having some, then it returned a few days ago. I'll be curious to see how long I go now without spam, but there are a couple of patterns the spam is inputting that I could deal with as well should not the do the trick entirely.
-
OK...I may have found out the problem. And yes, I'm a moron, and as I've posted on here several times this is why coding for a living would a) not be an option, and b) drive me insane: The problem: The field names were mismatched all along "email2" on the form, "Email2" on the enter.php. So when I changed both to "name" it 'stopped' working. It never worked. However, I found a similar solution, and it looks like I did it wrong the whole time: http://www.webdesignerforum.co.uk/topic/68584-anti-spam-form-without-captcha/ Basically, I needed to set up the hidden field with an empty value = '', so if it remained empty keep going, but if a spam bot fills it, stop and say "thanks for playing". Luckily my wild goose chases only happen about twice a year. One time we had this long a$$ discussion with two or three guys trying to help. Each one of us saying there is no reason this shouldn't work. It came down to having a comma instead of a period. Like anything, if you get enough eyes onto the subject, eventually you'll find the solution, even if it makes you look harder at your own code. I had kept the php files open since I made the changes, so I was able to CTRL-Z back to where they were before the change. That's when I noticed the difference in the capital E in Email2. Thank you for your time. I've tested the solution I linked, and it's working great...at least in terms of letting the form go through. We'll see how it does with spam over the next few days.
-
I understand what you're saying, but keep it on simple terms here. I have a form with a hidden field called "name". The form sends the user to enter.php where it's processed. The first thing enter.php does is... <?php // Make sure this person is real if (ISSET ($_POST['name'])) { echo 'Thank you for playing'; } // If so move on else { $nameFirst = $_POST['nameFirst']; $nameLast = $_POST['nameLast']; $nameParent = $_POST['nameParent']; $email = $_POST['email']; $addressHome = $_POST['addressHome']; $cityHome = $_POST['cityHome']; $stateHome = $_POST['stateHome']; $zipHome = $_POST['zipHome']; $phoneHome = $_POST['phoneParent']; $phoneMobile = $_POST['phoneMobile']; $school = $_POST['school']; $grade = $_POST['grade']; $coachSchool = $_POST['coachSchool']; $feet = $_POST['feet']; $inches = $_POST['inches']; From there it goes on to check if the Registrant is in the database. If so, it updates it. If not, it inserts him. Then it sends out emails and redirects the Registrant to the payment page. Now, if I change "name" to "name1", the form now works because "name1" doesn't get set because there is no "name1" in the form. Registrant information gets sent to database, emails get sent.