I don't know why I keep getting error messages for this line of code: -
$result = bool mysqli::real_query ( string $query )or die(mysqli::$error());
-
Is there some thing wrong with it? I've tried the object orientated style as well as the procedural style, but I get error messages with both.
9 1503
What exactly are you trying to do?
Normally to run a MySQL query in PHP, you would so something like: -
$getter=mysql_query($sql) or die(mysql_error)));
-
while($d=mysql_fetch_assoc($getter)){
-
}
-
I'm trying to bring all the records from a table in the database and display them on the web page. I used the method with mysql_query etc on my last website and had a lot of trouble when it came it deploying the site to a live server, so I'm trying to use the new and improved version with the mysqli extensions instead. I think it needs more detail as I keep getting error messages saying that the lines of code can't be used statically.
:facepalm: Because it's standard database practice to loop through the results. No database, as far as I know, can grab all the records into an array the way you're trying, especially since you're trying to make it into a bool. That's just incorrect....
Try this: -
$getter=mysql_query($sql);
-
while($d=mysql_fetch_assoc($getter)){
-
print $d[column_name];
-
}
-
No matter if you use the old version or the "new and fancier" mysql, you still need to loop through to print the results.
Edit:
SQLite can, but you're not using SQLite.
Thanks, but I am using a loop. A while loop to be exact. I just didn't add all the code to the question because I thought it was a simple question that someone would know the answer to right away. The problem is with the new MySQL extension. I'm fairly sure there must be something that I'm missing.
Would it be possible to post the full code?
Yes. -
<?php
-
$mysqli = mysqli_init();
-
if (!$mysqli) {die('mysqli_init failed');}
-
-
if (!$mysqli->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {die('Setting MYSQLI_INIT_COMMAND failed');}
-
-
if (!$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');}
-
-
if (!$mysqli->real_connect('localhost', 'root', '', 'pca')) {die('Connect Error (' . mysqli_connect_errno() . ') '.mysqli_connect_error());}
-
-
$query = "select * from news";
-
-
$result = bool mysqli->real_query ( string $query )or die(mysqli->$error());
-
-
$row = mysqli_result::fetch_array($result);
-
-
echo "<table class='displayReviews' border='1' style='width:100%;'>";
-
-
echo "<tr stlye='display:block;margin:0em auto;'><th>date</th><th>Headline</th><th>Body</th><th>Image</th></tr>";
-
-
while ($row = mysqli_result::fetch_array($result))
-
-
{
-
echo "<tr><td>";
-
echo $row['date'];
-
echo "</td><td>";
-
echo $row['headline'];
-
echo "</td><td>";
-
echo $row['body'];
-
echo "</td><td>";
-
echo $row['image'];
-
echo "</td><td>";
-
echo '<a href="edit.php">Edit</a>';
-
echo "</td><td>";
-
echo '<a href="delete.php">Delete</a>';
-
echo "</td></tr>";
-
}
-
echo "</table>";
-
-
$mysqli->close();
-
-
?>
-
Also, is there a better way than just sticking it in a table as well? I know tables are a bit old fashioned, but I suppose they still work ok.
Okay.....
So I got the code to work. Try the changes.
I also cleaned up your code to be more readable.
To be honest, I can already see TONS of future issues with this "new and improved" version of MySQL and I have a number of years coding for it. Messiest thing!
Also, please remember that if you have passwords set to no, you need to use null for that parameter. Is there anyway you can revert to the normal MySQL? You do know that just because it's installed, doesn't mean you have to use it... Have you tried the old code?
Anyway... Here's the code: -
<?php
-
$mysqli = mysqli_init();
-
if(!$mysqli){
-
print "MYSQLI failed...";
-
}
-
if(!$mysqli->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')){
-
}
-
if(!$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)){
-
print 'Setting MYSQLI_OPT_CONNECT_TIMEOUT failed';
-
}
-
$mysqli->real_connect('localhost', 'root',null,'pca');
-
if($mysqli->connect_error){
-
print 'Connect Error '.$mysqli->connect_error;
-
}
-
$query="select * from news";
-
$result=$mysqli->query($query);
-
print "<table class='displayReviews' border='1' style='width:100%;'>";
-
print "<tr stlye='display:block;margin:0em auto;'><th>date</th><th>Headline</th><th>Body</th><th>Image</th></tr>";
-
-
while($row=$result->fetch_assoc()){
-
print "<tr><td>";
-
print $row['date'];
-
print "</td>";
-
print "</td><td>";
-
print $row['headline'];
-
print "</td><td>";
-
print $row['body'];
-
print "</td><td>";
-
print $row['image'];
-
print "</td><td>";
-
print '<a href="edit.php">Edit</a>';
-
print "</td><td>";
-
print '<a href="delete.php">Delete</a>';
-
print "</td></tr>";*/
-
}
-
print "</table>";
-
$mysqli->close();
-
?>
-
http://cp.abelgancsos.com/project.php?id=405
If you must use the this version, this should be under your pillow: http://php.net/manual/en/book.mysqli.php
Good luck!
To answer your other question, it's a web standard to use tables when showing critical data as crawlers can't access the tables. I have designed and implemented a few special GUI's that use divs instead of tables, but you need to know how to prevent robots from crawling the pages (or be willing to put the site on your intranet instead) and understand how the design should work. Stay with tables, it might not look nice, but it's a web standard and tons of organizations use them. What you could do is spend hours styling the table with CSS.
Also, I just noticed that the edit and delete pages won't do anything as it's just going to the page. You should be passing an identifier for the row. May I ask what you're writing this for?
Thanks for the help Computerfox, that seems to have gotten it going.
The password thing is only because the site is still in development, that password will have to change once it goes into production.
I'm not really sure about which version of MySQL to use. I've had people telling me off for using the old version, now I have you saying it's better, but I don't really have enough experience yet to know which is better.
Thanks for the link to that manual, I've been trying to use it, but it doesn't seem to be working for me.
The table is fine. I heard someone saying they're very old fashioned but I think that was for general building in html, which I wouldn't really do in tables. I'm fine with having my database retrieved data in tables.
I'll be getting to the edit and delete pages next. I'm writing this for a new responsive site for my company. This is part of the news page. News items will be stored in the database, then displayed on the news page in the site. And, there's an admin section where the news items are generated.
Thanks again.
Anytime. Please mark the question as answered.
As an added note, I understand. Some developers like going with the newest and coolest stuff, but it's not always NEEDED to jump on the wagon. The "old" version of MySQL was actually stable and functional. I believe some of the reasons they changed it was to enable OOP style coding and of course prevent database injections. I've been using the same version since I built my server and even wrote API's for the database and all is fine.
A responsible developer tries not to fix what's not broken. I bet all your old code needed was some styling and it could have looked really good.
Anyway, I'm rambling. Please mark the question as answered and have a great night.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Chris Geerdink |
last post by:
combo with PHP. what is wrong with the Javascript?
else
{
include("mysql.php");
$query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES
('".$_POST."', '".$_POST."', '".$_POST."')");
?>
<script language="JavaScript">
<!--
|
by: asdf |
last post by:
Hello!
Can someone tell me whats wrong with this piece of code:
Option Compare Database
Option Explicit
Sub retrieve()
Dim rst As ADODB.Recordset
Dim i As Integer
|
by: Alexandre Martins |
last post by:
Provider=Microsoft.Jet.OLEDB.4.0;UserId=Admin;Password=teste;Data
Source=C:\Inetpub\wwwroot\inktoner\dados\db_inktoner.mdb;Persist Security
Info=True
I can't connect in my database !
whats wrong ??
tks
|
by: aa |
last post by:
When I am reading from local disk (d:), everithing is OK, but then I am
reading from map disk I am geting the this error. Whats wrong. Thanks
Server Error in '/Extra' Application.
----------------------------------------------------------------------------
----
The specified user does not exist.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more...
|
by: mahsa |
last post by:
Hi do you know whats wrong with this code?
<asp:HyperLink id="HLink_Help" runat="server" NavigateUrl='<%# "javascript:window.open('comments.aspx?id=1,width=500,height=600, scrollBars=yes');" %>'>Need Help?</asp:HyperLink>
--
mahsa
| |
by: blah |
last post by:
Hello everyone, Ive been trying to get my application to "click" on a
button in another application using SendMessage, Ive gotten this far
but Im not sure whats wrong with this code, here is the whole
application (its small for testing purposes) and it seems that window
wraps the text, at least when I preview this post:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
|
by: '~=_Slawek_=~' |
last post by:
$DOW = (jddayofweek(unixtojd(mktime(1, 1, 1, $month, $day, $year)))+6)%7;
$DOW= (jddayofweek(juliantojd($month, $day, $year))+6)%7;
The results are supposed to be the same, but they are not. Whats wrong? Any
clues?
|
by: Jim Andersen |
last post by:
I am using Microsoft.ApplicationBlocks.Data (v 2.0.0.0).
I have this parameter array I pass to a stored procedure. The last one is an
output parameter.
So I did this:
Line 1: arParms(8) = New SqlClient.SqlParameter("@MyParam", SqlDbType.Int,
4, ParameterDirection.Output)
Line 2: arParms(8).Direction = ParameterDirection.Output
|
by: Mike Barnard |
last post by:
It's a simple test... VERY SIMPLE. But...
In an external stlyesheet some attributes don't show. With the same
styles cut and pasted to the test internally it works as expected.
Anyone tell me why? Its probably sooooooo obvious, but it is 1.19 am!
Thanks.
www.thunderin.co.uk/
|
by: islayer |
last post by:
can someone tell me what is wrong with the bold code? i am just learning perl. the program should create a perl file with a random name (5 letters, followed by a number), but the name is always just the number. whats wrong with my code?
#!/usr/bin/perl
use Fcntl;
@array = (a..z);
srand;
foreach (1..5)
{
$name = int(rand scalar(@array));
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |