Jump to content
Larry Ullman's Book Forums

Joel

Members
  • Posts

    6
  • Joined

  • Last visited

Joel's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. In this example why does the procedural way fail with this error: Error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, object given in /Users/joel/Sites/people_test/public_html/index.php on line 14 PHP: $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); $q = "SELECT first_name, last_name FROM person LIMIT 0,30"; $r = mysqli_query($dbc, $q); Procedural: while($data = mysql_fetch_assoc($r)) { $rows[] = $data; } //prints out null echo json_encode($rows); OOP: while($data = $r->fetch_assoc()) { $rows[] = $data; } echo json_encode($rows); I thought I was doing the procedural way right from reading the PHP.net fetch_assoc() procedural and oop examples. Obviously I'm missing something. Could use some help seeing what it is.
  2. Found it outside the forums. I thought the book sections there were just links to the forums. Book scripts and SQL commands http://www.larryullman.com/books/php-and-mysql-for-dynamic-web-sites-visual-quickpro-guide-4th-edition/
  3. @edward there are also online tools that will format code in a way that's easier to read. Google JavaScript beautifier. Handles HTML code too and there are others too.
  4. Not as clean cut as D.R.Y or K.I.S.S but definitely hard to forget now lol
  5. I know I'm probably missing the obvious but where are the chapter work files? Specifically the SQL queries to insert data.
×
×
  • Create New...