Mysql help!!

  • kej0283
  • Novice
  • Novice
  • kej0283
  • Posts: 18

Post 3+ Months Ago

What are you suppose to type here $yourfield = 'your_field'; to connect? What does yourfield mean?

PHP Code: [ Select ]
<?php
//Connect To Database
$hostname='username';
$username='username';
$password='your password';
$dbname='dbname';
$usertable='your_tablename';
$yourfield = 'your_field';
 
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
 
$query = 'SELECT * FROM $usertable';
$result = mysql_query($query);
if($result) {
    while($row = mysql_fetch_array($result)){
        $name = $row['$yourfield'];
        echo 'Name: '.$name;
    }
}
  1. <?php
  2. //Connect To Database
  3. $hostname='username';
  4. $username='username';
  5. $password='your password';
  6. $dbname='dbname';
  7. $usertable='your_tablename';
  8. $yourfield = 'your_field';
  9.  
  10. mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
  11. mysql_select_db($dbname);
  12.  
  13. $query = 'SELECT * FROM $usertable';
  14. $result = mysql_query($query);
  15. if($result) {
  16.     while($row = mysql_fetch_array($result)){
  17.         $name = $row['$yourfield'];
  18.         echo 'Name: '.$name;
  19.     }
  20. }
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

$yourfield would be the name of the column for whatever piece of data you are extracting. Also you may want to change:

This...
$query = 'SELECT * FROM $usertable';
To...
$query = 'SELECT * FROM '.$usertable;

And this...
$row['$yourfield']
To...
$row[$yourfield]
  • kej0283
  • Novice
  • Novice
  • kej0283
  • Posts: 18

Post 3+ Months Ago

Thank you! I got it..

Why can't you connect like this anymore??

PHP Code: [ Select ]
$con = mysql_connect("hostname", "username", "password") or die('Could not connect to server');
mysql_select_db("groceystore", $con) or die('Could not connect to database');
  1. $con = mysql_connect("hostname", "username", "password") or die('Could not connect to server');
  2. mysql_select_db("groceystore", $con) or die('Could not connect to database');


I'm having trouble connecting to my project because I can't use that in technique
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

That should work fine. Have you double-checked to ensure you've got the right parameters plugged in?
  • kej0283
  • Novice
  • Novice
  • kej0283
  • Posts: 18

Post 3+ Months Ago

I'm using godaddy.. and they use this

PHP Code: [ Select ]
<?php
//Connect To Database
$hostname='username';
$username='username';
$password='your password';
$dbname='dbname';
$usertable='your_tablename';
$yourfield = 'your_field';
 
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
 
$query = 'SELECT * FROM $usertable';
$result = mysql_query($query);
if($result) {
while($row = mysql_fetch_array($result)){
$name = $row['$yourfield'];
echo 'Name: '.$name;
}
}
  1. <?php
  2. //Connect To Database
  3. $hostname='username';
  4. $username='username';
  5. $password='your password';
  6. $dbname='dbname';
  7. $usertable='your_tablename';
  8. $yourfield = 'your_field';
  9.  
  10. mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
  11. mysql_select_db($dbname);
  12.  
  13. $query = 'SELECT * FROM $usertable';
  14. $result = mysql_query($query);
  15. if($result) {
  16. while($row = mysql_fetch_array($result)){
  17. $name = $row['$yourfield'];
  18. echo 'Name: '.$name;
  19. }
  20. }


for there mysql connection but my project does it the other way. So, do I set parameters to make this work instead??

PHP Code: [ Select ]
$con = mysql_connect("hostname", "username", "password") or die('Could not connect to server');
mysql_select_db("groceystore", $con) or die('Could not connect to database');
  1. $con = mysql_connect("hostname", "username", "password") or die('Could not connect to server');
  2. mysql_select_db("groceystore", $con) or die('Could not connect to database');
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Either way would suffice. I assume you *are* plugging in YOUR hostname, username, and password where it says as much - correct?
  • kej0283
  • Novice
  • Novice
  • kej0283
  • Posts: 18

Post 3+ Months Ago

yes! I am.
  • kej0283
  • Novice
  • Novice
  • kej0283
  • Posts: 18

Post 3+ Months Ago

Got a mysql qustion that i"m stuck on.. I have in my data base.. time: which as the datetime function..(think thats what its called) and one that says time2 where it just the date. How do you join those together.. in php. So that it show up on the screen for example: October 2, 2009 1:00pm - 4:00pm?
  • kej0283
  • Novice
  • Novice
  • kej0283
  • Posts: 18

Post 3+ Months Ago

PHP Code: [ Select ]
<div class="header">
<?php include ("header2.php") ?>
</div>
<?php
 
 
require_once("configproject.php");
 
 
 
// Number of records to show per page:
$display = 8;
 
// Determine how many pages there are.
if (isset($_GET['np'])) { // Already been determined.
 
   $num_pages = $_GET['np'];
 
} else { // Need to determine.
 
   // Count the number of records
   $query = "SELECT COUNT(*) FROM events";
   $result = mysql_query ($query)or die("first query");
$query2 = "SELECT COUNT(*) FROM events";
   $result = mysql_query ($query2)or die("first query");
   $row = mysql_fetch_array ($result, MYSQL_NUM);
   $num_records = $row[0];
 
   // Calculate the number of pages.
   if ($num_records > $display) { // More than 1 page.
      $num_pages = ceil ($num_records/$display);
   } else {
      $num_pages = 1;
   }
   
} // End of np IF.
 
// Determine where in the database to start returning results.
if (isset($_GET['s'])) {
   $start = $_GET['s'];
} else {
   $start = 0;
}
 
 
 
   
// Make the query.
$query = "SELECT id, event, event_descrption,place, thumbdata,DATE_FORMAT(stime, '%M %d, %Y') AS st, TIME_FORMAT(stime, '%l:%i, %p') AS stime,  DATE_FORMAT(etime, '%M %d, %Y'), email FROM events LIMIT $start, $display";
 
$query2 = "SELECT CONCAT( stime, ' ', etime )
FROM `events";
$result = mysql_query ($query) or die("second query"); // Run the query.
$result = mysql_query ($query2) or die("second query"); // Run the query.
$num = mysql_num_rows($result);
  1. <div class="header">
  2. <?php include ("header2.php") ?>
  3. </div>
  4. <?php
  5.  
  6.  
  7. require_once("configproject.php");
  8.  
  9.  
  10.  
  11. // Number of records to show per page:
  12. $display = 8;
  13.  
  14. // Determine how many pages there are.
  15. if (isset($_GET['np'])) { // Already been determined.
  16.  
  17.    $num_pages = $_GET['np'];
  18.  
  19. } else { // Need to determine.
  20.  
  21.    // Count the number of records
  22.    $query = "SELECT COUNT(*) FROM events";
  23.    $result = mysql_query ($query)or die("first query");
  24. $query2 = "SELECT COUNT(*) FROM events";
  25.    $result = mysql_query ($query2)or die("first query");
  26.    $row = mysql_fetch_array ($result, MYSQL_NUM);
  27.    $num_records = $row[0];
  28.  
  29.    // Calculate the number of pages.
  30.    if ($num_records > $display) { // More than 1 page.
  31.       $num_pages = ceil ($num_records/$display);
  32.    } else {
  33.       $num_pages = 1;
  34.    }
  35.    
  36. } // End of np IF.
  37.  
  38. // Determine where in the database to start returning results.
  39. if (isset($_GET['s'])) {
  40.    $start = $_GET['s'];
  41. } else {
  42.    $start = 0;
  43. }
  44.  
  45.  
  46.  
  47.    
  48. // Make the query.
  49. $query = "SELECT id, event, event_descrption,place, thumbdata,DATE_FORMAT(stime, '%M %d, %Y') AS st, TIME_FORMAT(stime, '%l:%i, %p') AS stime,  DATE_FORMAT(etime, '%M %d, %Y'), email FROM events LIMIT $start, $display";
  50.  
  51. $query2 = "SELECT CONCAT( stime, ' ', etime )
  52. FROM `events";
  53. $result = mysql_query ($query) or die("second query"); // Run the query.
  54. $result = mysql_query ($query2) or die("second query"); // Run the query.
  55. $num = mysql_num_rows($result);


I figure out that I need to cat both files but how do you write so it works?

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 82 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.