Jump to content

webguync

Members
  • Posts

    951
  • Joined

  • Last visited

Everything posted by webguync

  1. This is probably easy, but I am a little rusty. How would I turn these rows of data into clickable links. Not sure how where to add the <a href="linkURL"></a> part. <td><?php echo $record['email_t'];?></td> <td><?php echo $record['url_t'];?></td> Thanks in advance!
  2. I am trying to make a few HTML fields into hyperlinks that are pulling data from MySQL into PHP. My syntax is currently off, so I need some assistance. I have tried this. <td><a href="mailto:<?php echo $record['email_t'];?></a></td> <td><a href="<?php echo $record['url_t'];?></a></td> I am basically just trying to make the email a mailto link and the url field a hyperlink. Any help is greatly appreciated!
  3. I'm a little rusty at this. I have a field in MySQL set to type of timestamp and I am displaying it in an HTML table and it displays as 2012-10-14 13:09:07. I would rather have at display as Sunday, October 14th at 3:09. The code to pull the data is as follow: <?php mysql_connect("localhost","uname","pw");//database connection mysql_select_db("DBName"); $SQL = "SELECT * FROM organization ORDER BY time_created_t ASC"; $result = mysql_query($SQL); lt while($data = mysql_fetch_row($result)){ echo("<tr><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td><td>$data[4]</td><td>$data[5]</td><td>$data[6]</td><td>$data[7]</td><td>$data[8]</td><td>$data[9]</td><td>$data[10]</td><td>$data[11]</td><td>$data[12]</td></tr>"); } ?> the timestamp is in <td>$data[12]</td>
  4. can you provide an example of the SQL for searching a Phrase?
  5. I am working on Query application which returns results from a MySQL DB. The database consist of players from various sports teams, and list their name, city, sport, etc. The issue is if you type in a search terms from one of the fields any result will return and I only want unique results. For instance if you type in 'New York Giants', you will get a return of all the New York teams, even though I have city and team name in two different columns. The Query is matching 'New York and returning all results with that in the Query. Anyway here is my SQL code. SELECT sport,first_name,last_name,MVP,city,Picture,team FROM players WHERE MATCH(sport,first_name,last_name,MVP,city,team,Picture) AGAINST('$query' IN BOOLEAN MODE)");
  6. I am trying to get the error if($type == "results") { $sql = mysql_query("SELECT sport,first_name,last_name,MVP,team FROM players WHERE MATCH(sport,first_name,last_name,MVP,team) AGAINST('$query' IN BOOLEAN MODE)AND concat(sport,first_name,last_name,MVP,team) like '%$query'"); echo mysql_error($sql); the mysql_error(): supplied resource is not a valid MySQL-Link resource in C:\xampp\htdocs\Testing\DB_Search\search2.php on line 36
  7. thanks for the reply I am getting an error with my Query now though. <?php $dbhost = "localhost"; $dbuser = "webguync"; $dbpass = "Phoenix90"; $dbname = "test"; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); if(isset($_GET['query'])) { $query = $_GET['query']; } else { $query = ""; } if(isset($_GET['type'])) { $type = $_GET['type']; } else { $query = "count"; } if($type == "count") { $sql = mysql_query("SELECT count(category_id) FROM players WHERE MATCH(sport,first_name,last_name,MVP,team) AGAINST('$query' IN BOOLEAN MODE) AND lower(concat(sport,first_name,last_name,MVP,team)) like %lower($query)$"); $total = mysql_fetch_array($sql); $num = $total[0]; echo $num; } if($type == "results") { $sql = mysql_query("SELECT sport,first_name,last_name,MVP,team FROM players WHERE MATCH(sport,first_name,last_name,MVP,team) AGAINST('$query' IN BOOLEAN MODE) AND lower(concat(sport,first_name,last_name,MVP,team)) like %lower($query)$ "); echo "<table>"; echo "<tr>"; echo "<th>First Name</th><th>Last Name</th><th>Team</th><th>MVP</th>"; while($row = mysql_fetch_assoc($sql)) { $class = ($row['MVP']) ? 'class="MVP"' : ''; $mvpText = ($row['MVP']) ? 'MVP' : ''; echo "<tr>\n"; echo " <td {$class}>{$row['first_name']}</td>\n"; echo " <td {$class}>{$row['last_name']}</td>\n"; echo " <td {$class}>{$row['team']}</td>\n"; echo " <td {$class}>{$mvpText}</td>\n"; echo "</tr>\n"; } echo "</table>"; } echo $sql; mysql_close($conn); ?> The error is "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in search2.php on line 42
  8. see I knew there was a better way! Thanks this is a much better implementation.
  9. I need some help adjust a search form that uses PHP/MySQL/AJAX/JQuery. I am not sure what area needs to be adjusted, but I think it's in the Query. The search from searches across the MySQL database of sports team info and works fine. the only problem is in the return of one key word when I needed the exact match of two or more words. For instance you type in 'Miami Heat' and the results returned are for 'Miami Heat' and 'Miami Dolphins', so anything with the key word Miami is returned. Here is the PHP code <?php $dbhost = "localhost"; $dbuser = "username"; $dbpass = "pw"; $dbname = "db_name"; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); if(isset($_GET['query'])) { $query = $_GET['query']; } else { $query = ""; } if(isset($_GET['type'])) { $type = $_GET['type']; } else { $query = "count"; } if($type == "count") { $sql = mysql_query("SELECT count(category_id) FROM players WHERE MATCH(sport,first_name,last_name,MVP,team) AGAINST('$query' IN BOOLEAN MODE)"); $total = mysql_fetch_array($sql); $num = $total[0]; echo $num; } if($type == "results") { $sql = mysql_query("SELECT sport,first_name,last_name,MVP,team FROM players WHERE MATCH(sport,first_name,last_name,MVP,team) AGAINST('$query' IN BOOLEAN MODE)"); echo "<table>"; echo "<tr>"; echo "<th>First Name</th><th>Last Name</th><th>Team</th><th>MVP</th>"; while($array = mysql_fetch_array($sql)) { $sport = $array['sport']; $first_name = $array['first_name']; $last_name = $array['last_name']; $team = $array['team']; $MVP = $array['MVP']; echo "<tr><td>" . $first_name . "</td>\n<td>". $last_name ."</td>\n<td>" .$team."</td>\n<td> . $MVP .</td>\n</tr>\n"; } echo "</table>";=\ } mysql_close($conn); ?>
  10. I am pretty sure it worked before. What I am trying to do is add CSS to every record in the database with the value MVP. The column is also called MVP. As an example I want to add a background so in my CSS. .MVP{ background:red; } and I want that class added to every record with the value MVP in the MVP column. my while loop while($array = mysql_fetch_array($sql)) { $sport = $array['sport']; $first_name = $array['first_name']; $last_name = $array['last_name']; $team = $array['team']; $MVP = $array['MVP']; echo "<tr><td>" . $first_name . "</td>\n<td>". $last_name ."</td>\n<td>" .$team."</td>\n<td> . $MVP .</td>\n</tr>\n"; } there is probably an easier way of doing it.
  11. I had this working before, but my coding structure has changed a bit and need help with syntax. My function I have down ok. function cssfrommvp($mvp) { $class = array('MVP' => 'MVP'); return $class[$mvp]; } this is how I would add the class to a <td> with $row. echo "<td class=\"".cssfrommvp($row['mvp'])."\">".$row['mvp']."</td>\n"; now using $array <td> . $MVP .</td>\n</tr> how would I do the same thing as done before with $row?
  12. ok cool, it sorta kind almost works now, but the Query is still wrong. My table is displayed below the form, so it's pulling the data, but my query is now. SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.category_id = 'Football' the query is pulling the corresponding sport instead of the id integer it should be: SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.category_id = '4'
  13. Thanks I will try that. Would that code be all I need to replace this? function showPlayers(str) { var xmlhttp; if (str=="") { document.getElementById("DataDisplay").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); else {// code for IE6, IE5 } xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("DataDisplay").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","Query.php?category_id="+str,true); xmlhttp.send(); } or would I need to add type:"GET"; and other stuff?
  14. not getting the alert which I guess means the conditions are being met.
  15. when I go to Query.php in the browser it echoes out as: SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.category_id = ''
  16. thanks. I am getting the alert now. The value is indeed holding.
  17. I didn't get the alert when I selected a sport. My code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB"> <head> <title>Inspired Evolution : : AJAX Example</title> <link rel="stylesheet" type="text/css" href="Form.css" media="screen" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("tr:odd").addClass("odd"); }); </script> <script type="text/javascript"> function showPlayers(str) { var xmlhttp; if (str=="") { document.getElementById("DataDisplay").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); else {// code for IE6, IE5 } xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("DataDisplay").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","Query.php?category_id="+str,true); xmlhttp.send(); } </script> <script type="text/javascript"> function showPlayers(str) { alert(str); } </script> </head> <body> <h1 id="Tutoring">Inspired-Evolution.com : : AJAX Example</h1> <p>Below is an application example which utilizes the following web technologies to display the data. HTML, CSS, PHP/MySQL, JQuery and AJAX.</p> <?php #connect to MySQL $conn = mysql_connect( "internal-db.s118256.gridserver.com","db118256_Bruce","Phoenix90") or die( "You did not successfully connect to the DB!" ); #select the specified database $db = mysql_SELECT_DB ("db118256_MyTestDB", $conn ) or die ( "Error connecting to the database test!"); ?> <form name="sports" id="sports"> <legend>Select a Sport</legend> <select name="category_id" onchange=showPlayers(this.options[this.selectedIndex].value);"> <option value="">Select a Sport:</option> <?php $sql = "SELECT category_id, sport FROM sports ". "ORDER BY sport"; $db = mysql_query($sql); while($row = mysql_fetch_array($db)) { echo "<option value=\"".$row['category_id']."\">".$row['sport']."</option>\n "; } ?> </select> </form> <br /> <div id="DataDisplay"></div> </body> </html>
  18. thanks for the replies, but my problem with the data not displaying still exist. I changed the select to <select name="category_id" onchange=showPlayers(this.options[this.selectedIndex].value);"> still doesn't display. I think the issue may be with my SQL query not executing the WHERE clause properly. When I echo it out I STILL get. SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.category_id = ''
  19. I had this working, but when I try and get fancy and use AJAX the data doesn't display. I think this is a PHP problem though. My code for the select form including AJAX code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB"> <head> <title>AJAX Example</title> <link rel="stylesheet" type="text/css" href="Form.css" media="screen" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("tr:odd").addClass("odd"); }); </script> <script type="text/javascript"> function showPlayers(str) { var xmlhttp; if (str=="") { document.getElementById("DataDisplay").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); else {// code for IE6, IE5 } xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("DataDisplay").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","Query.php?category_id="+str,true); xmlhttp.send(); } </script> </head> <body> <h1">AJAX Example</h1> <?php #connect to MySQL $conn = @mysql_connect( "localhost","username","pw") or die( "You did not successfully connect to the DB!" ); #select the specified database $rs = @mysql_SELECT_DB ("MyDB", $conn ) or die ( "Error connecting to the database test!"); ?> <form name="sports" id="sports"> <legend>Select a Sport</legend> <select name="category_id" onChange="showPlayers(this.value)"> <option value="">Select a Sport:</option> <?php $sql = "SELECT category_id, sport FROM sports ". "ORDER BY sport"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['category_id']."\">".$row['sport']."</option>\n "; } ?> </select> </form> <br /> <div id="DataDisplay"></div> </body> </html> Query.php <?php #get the id $id=$_GET["category_id"]; #connect to MySQL $conn = @mysql_connect( "localhost","username","pw") or die( "Error connecting to MySQL" ); #select the specified database $rs = @mysql_SELECT_DB ("MyDB", $conn ) or die ( "Could not select that particular Database"); #$id="category_id"; #create the query $sql ="SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.category_id = '".$id."'"; echo $sql; #execute the query $rs = mysql_query($sql,$conn); #start the table code echo "<table><tr><th>Category ID</th><th>Sport</th><th>First Name</th><th>Last Name</th></tr>"; #write the data while( $row = mysql_fetch_array( $rs) ) { echo ("<tr><td>"); echo ($row["category_id"] ); echo ("</td>"); echo ("<td>"); echo ($row["sport"]); echo ("</td>"); echo ("<td>"); echo ($row["first_name"]); echo ("</td>"); echo ("<td>"); echo ($row["last_name"]); echo ("</td></tr>"); } echo "</tr></table>"; mysql_close($conn); ?> I think the problem is either with this part in the AJAX xmlhttp.open("GET","Query.php?category_id="+str,true); or most likely in my Query.php code when I wasn't using AJAX and using POST it worked fine, but adding the AJAX stuff and GET it doesn't work. When I echo out the SQL the result is SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.category_id = '' so the category_id is not being selected properly and that is the primary key/foreign key in the MySQL table which connects the JOIN.
  20. I almost have this right, but not quite. I am trying to echo out the average score if a person scored above 70 and my averaging isn't correct. It should echo out 89, but instead the number is 63.25. The averaging is the only part not working. Everything else works as intended. I might not have my curly braces in the proper order or something. I think it's something stupid I am forgetting. Here is my code. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Array Test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php function array_average_nonzero($scores) { return array_sum($scores) / count(array_filter($scores)); } $scores["Tim"] = 98; $scores["Tom"] = 80; $scores["Mike"] = 50; $scores["Jason"] = 25; foreach( $scores as $key => $value) if($value < 70){ echo "$key scored a $value which is less than 70. <br />\n"; } elseif ($value < 70); { echo "The average score of those who scored over 70 is: " .array_sum($scores) / count($scores) . "<br />"; } ?> </body> </html>
  21. I figured this out. Changed $_GET to $_POST, added a submit button and changed to method="POST", changed a little bit of the Query and voila!
  22. I know that is a lot of code. A few more lines I forgot to add. I changed in my form code to <form name="sports" id="sports" action="Query.php" method="post" > my also added in my php code $id=["category_id"]; #create the query $sql ="SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.sport = '.$_GET[$id]'"; still doesn't work but I think I am getting close.
×
×
  • 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.