Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently May 17th, 2024, 11:51 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Questions about reading multiple records from MySQL database
PostPosted: September 3rd, 2015, 3:53 pm 
Offline

Joined: August 24th, 2015, 8:42 pm
Posts: 42
Location: Wesley Chapel, FL, USA
Opus: Opus Pro 9.x
OS: Windows 10
System: MSI Dragon Laptop - 8 Core i7, 32gb ram, 2tb hd, GeForce GTX 980
I have been following the tutorials on how to write and read from a external MySQL database.

The writing to database tutorial I have accomplished and with the exception of image data uploading as images, everything else went amazingly well.

I thought reading from the database would be much simpler.

I was wrong. I forgot about how to read ALL the records and then put them into some kind of array - something like that.

I wrote the load.php script (username and password blanked out for obvious reasons):

Code:
<?php

$DBhost = "mfelkerco.com";
$DBuser = "XXXXXXX";
$DBpass = "XXXXXXXXXXX";
$DBName = "mfelker_TB3Memdb";

$connect = mysql_connect($DBhost,$DBuser,$DBpass);
$db = mysql_select_db($DBName,$connect);
$query = "SELECT * FROM members";
$result = mysql_query($query, $connect);

$row = mysql_fetch_array($result );
$data = "&memberid=".$row['memberid']."&membername=".$row['membername']."&membertitle=".$row['membertitle']."&memberpic=".$row['memberpic']."&membercategory=".$row['membercategory']."&businessname=".$row['businessname']."&officephone=".$row['officephone']."&mobilephone=".$row['mobilephone']."&faxphone=".$row['faxphone']."&emailaddr=".$row['emailaddr']."&businesswebsite=".$row['businesswebsite']."&businessdesc=".$row['businessdesc']."&facebooklink=".$row['facebooklink']."twitterlink=".$row['twitterlink']."&linkedinlink=".$row['linkedinlink']."&youtubelink=".$row['youtubelink']."&myspacelink=".$row['myspacelink']."&instagramlink=".$row['instagramlink']."&googlepluslink=".$row['googlepluslink']."&pinterestlink=".$row['pinterestlink']."&isplatinummember=".$row['isplatinummember']."&memberjoindate=".$row['memberjoindate']."&bcfrontpic=".$row['bcfrontpic']."&bcbackpic=".$row['bcbackpic']."&platinumbannerpic=".$row['platinumbannerpic'];
echo $data

?>

and then created the form (member directory form) in Opus Pro to read from the database. I followed the tutorial to the letter (I simply have more fields, though) and
created all the text boxes with variables and did the 'on show' trigger with 'post to web' action (with the correct URL for the load.php file) and put all the strings and
variables as a multi in the DESTINATION tab. I do get the 1st record to show, but no others. I am not sure how to go back and forth between records.

One thing I did notice is that in the tutorial, they assume one record only, so memberid (my auto increment field) is not accounted for.

I also put forward, backward and search buttons on the form. I want forward and backward to simply go back and forth between database records. The search button goes
to another form with search boxes for name and category (those do not show up either). The idea there is to have a listbox (I would prefer a dropdown box, but cannot find
one) so that the user can select the name or category and then find that record and go to it in the member directory form.

My questions are: How can I read the memberid field and then use that to go back and forth between records? How can I read ALL records in the database (from a specific field -
membername and membercategory) and have them all show up in list boxes? How can I choose a record from a listbox (name or category) and then load that specific data to
the member directory form text boxes (for example, in the names list box there are 20 names and I pick one, now I want that name's record to show up on the member
directory form)?

I can post the project file if needed.

Thank you for your help.

Mike

_________________
You Dream It - We Create It
www.supersynths.com - Amazing Synths and Sounds


For this message karmacomposer has been thanked by : mackavi


Last edited by karmacomposer on September 3rd, 2015, 4:13 pm, edited 5 times in total.

Top
 Profile Visit website  
 
 Post subject: Re: Having problems reading from a MySQL database
PostPosted: September 3rd, 2015, 4:01 pm 
Offline

Joined: August 24th, 2015, 8:42 pm
Posts: 42
Location: Wesley Chapel, FL, USA
Opus: Opus Pro 9.x
OS: Windows 10
System: MSI Dragon Laptop - 8 Core i7, 32gb ram, 2tb hd, GeForce GTX 980
...and then I noticed, upon reading my code back, that the darn table was wrong. I changed it to 'members' and it read (yay). However, it only read ONE record and there are more than one record in the database. I will modify my original post above to reflect my stupid mistake.

How do I show ALL name and ALL category entries in the list boxes and then how do I show the clicked on choice in the member directory form.

So, I DID get loading the data from the 1st record done! Now I need to figure out the rest.

Thank you for your help.

Mike

_________________
You Dream It - We Create It
www.supersynths.com - Amazing Synths and Sounds


For this message karmacomposer has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: Questions about reading multiple records from MySQL data
PostPosted: September 3rd, 2015, 4:42 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
mysql is deprecated - you should be using mysqli or PDO.

Depending on your PHP version, you could then use something like mysqli_fetch_all to return the set as an array and json_encode to echo it back to the JavaScript as a usable string.

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Questions about reading multiple records from MySQL data
PostPosted: September 3rd, 2015, 4:47 pm 
Offline

Joined: August 24th, 2015, 8:42 pm
Posts: 42
Location: Wesley Chapel, FL, USA
Opus: Opus Pro 9.x
OS: Windows 10
System: MSI Dragon Laptop - 8 Core i7, 32gb ram, 2tb hd, GeForce GTX 980
mackavi wrote:
mysql is deprecated - you should be using mysqli or PDO.

Depending on your PHP version, you could then use something like mysqli_fetch_all to return the set as an array and json_encode to echo it back to the JavaScript as a usable string.

</mack>


And is there tutorials or documentation for this? The ONLY thing I could find on the Opus Pro digitalworkshop website is three tutorials on writing to and reading from a MySQL database - and so far they are working.

I have not heard of mysqli or PDO. I am using a MySQL database on a apache server using PHP.

Thank you for the answer, but I need a bit more to go on.

Mike

_________________
You Dream It - We Create It
www.supersynths.com - Amazing Synths and Sounds


For this message karmacomposer has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: Questions about reading multiple records from MySQL data
PostPosted: September 4th, 2015, 12:07 am 
Offline

Joined: August 24th, 2015, 8:42 pm
Posts: 42
Location: Wesley Chapel, FL, USA
Opus: Opus Pro 9.x
OS: Windows 10
System: MSI Dragon Laptop - 8 Core i7, 32gb ram, 2tb hd, GeForce GTX 980
Does this look correct for the load.php:

Code:
<?php

$DBhost = "mfelkerco.com";
$DBuser = "xxxxxxx";
$DBpass = "xxxxxxxxxxx";
$DBName = "mfelker_TB3Memdb";

$connect = mysqli_connect($DBhost,$DBuser,$DBpass);
$db = mysqli_select_db($DBName,$connect);
$query = "SELECT * FROM members";
$result = mysqli_query($query, $connect);

$result = mysqli_query($connect,"SELECT * FROM members");
$row = mysqli_fetch_array($result);
$data = "&memberid=".$row['memberid']."&membername=".$row['membername']."&membertitle=".$row['membertitle']."&imgpicpath=".$row['imgpicpath']."&membercategory=".$row['membercategory']."&businessname=".$row['businessname']."&officephone=".$row['officephone']."&mobilephone=".$row['mobilephone']."&faxphone=".$row['faxphone']."&emailaddr=".$row['emailaddr']."&businesswebsite=".$row['businesswebsite']."&businessdesc=".$row['businessdesc']."&facebooklink=".$row['facebooklink']."twitterlink=".$row['twitterlink']."&linkedinlink=".$row['linkedinlink']."&youtubelink=".$row['youtubelink']."&myspacelink=".$row['myspacelink']."&instagramlink=".$row['instagramlink']."&googlepluslink=".$row['googlepluslink']."&pinterestlink=".$row['pinterestlink']."&isplatinummember=".$row['isplatinummember']."&memberjoindate=".$row['memberjoindate']."&bcfrontpic=".$row['bcfrontpic']."&bcbackpic=".$row['bcbackpic']."&platinumbannerpic=".$row['platinumbannerpic'];
echo $data;

?>


Where would I include javascript code to fetch data, such as memberid?

Mike

_________________
You Dream It - We Create It
www.supersynths.com - Amazing Synths and Sounds


For this message karmacomposer has been thanked by : mackavi


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 5 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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group