How to access elements in laravel using pgsql as database? - php

I am currently learning laravel with pgsql as the defaut database.
I was reading the laravel tutorial online and I am in the chapter "Working with database".
I copy pasted the code for retrieving records but it doesn't work so I am assuming that it is probably because the tutorial uses MySQL while I'm using postgres.
I modified the code a bit and ended up with these:
StudentController.php
stud_view.php
All I'm getting is a table with headers but it's empty.
I noticed that as I add more tuples in the student table the table being showed by the stud_view is getting bigger but still empty so the Studentontroller must be correct right? The $user->id line of code must then be wrong. Well how do I access the elements then? By the way my student table has attributes name and id only. Thanks for the help.

I realized that my mistake was the filename! I should've saved it as stud_view.blade.php After doing so it worked. I don't understand why though because I thought blade was just used for styling.

Related

Using & with fpdf and mysql causes problems

It seems i have stumbled onto a unforeseen problem with fpdf when using & in a sentence.
My php file gets information from a mysql database. And unfortunately I noticed if the field contains a & symbol the command fails. Basically what happens is if the sentence says Me, my partner & our friends the fpdf command only posts Me, my partner and ignores the rest...
I do not use the $_GET to pass the values, but rather $_POST, so i do not believe the & sign should conflict should it?
I have been spending quite some time searching for answers, but I do not see any mention of it...
Any assistance would be great.

php code drupal database get

Ok I am using drupal 7.
I need to get information out of some tables so I can read them in a iPhone app. I found out I need a php code to convert a table to json format. I need the code to go to a database "x" then to table "y". Then list entity_id and name from all the fields. This will be a read only. I don't know the first thing about php code. Can anyone point me in the right direction? Thanks
Follow the steps :-
Learns PHP :-)
learn how drupal works
Learn Drupal hooks
Drupal query.
Once you are inside drupal you dont need to coonect to drupal database, its handled by Drupal.
After this you can use hook_menu and in call back function you can return required JSON output.
Use that link in your application.
Chheers!!!

How can I sort multiple tables i export from an sql database to excel by date?

I have searched for help with this extensively but haven't been able to figure it out. This is my first attempt at asking a question here so please bare with.
I have a project called www.farmathand.com where farmers keep track of their field activities through multiple pre-defined forms and a few dynamic forms. These forms then have an associated date with them to keep a record of when something was done. Here's a screen shot
Farmers have the ability to export all their entered information into an excel file. The problem I am having is figuring out a solution so sort the activities by date. Currently I have simple export code that looks and print data from each table (i.e. each type of activity) then moves on the to the next able. The fields in each table differ as you can see in the image.
Here is a screen shot of an excel file for the above example:
What i would like to be able to do is sort the activities by the date. So in the example in the above image. Line 7 would be at the top or like one should be line 6.
I was wondering if anyone had any suggesting or could guide me to the appropriate reference. The data base is a mysql database. I'm running php scripts currently.
If I understand your question correctly then what you want is to include an ORDER BY clause in your select query to sort the data. More information here:
http://dev.mysql.com/doc//refman/5.0/en/sorting-rows.html

How can I write data to an excel table from textarea?

I am new in coding and sufferin from some basic issues. I searched for a topic to find the answer that I need but I could not find. I've been trying to write and searching codes for writting into xls file for 3 days but could not find a suitable one. The problem is:
I created a page with textareas and submit/reset button like that and I've got an excel table in document classgrades.xls. The colums of that table are named Name, Midterm1, Midterm2, Final, Attendance and Average.
Now, I am trying to write a code which automatically adds a new row and writes user inputs from textares into the excel table. If you help I appreciate very much and if you write the code briefly I can understand better.
The class I use to modify Excel documents is PHPExcel. Was at http://phpexcel.codeplex.com/ but I just googled and it's moved to GitHib https://github.com/PHPOffice/PHPExcel.
Small warning: I have found it occasionnally buggy (turn off "NOTICE" and "WARNING" errors before diving in, for example - or at least you did when I last used it) but otherwise it's easy to use.
It has some nice classes to navigate the workbooks and add rows. No point quoting examples here as there are lots of examples in the "test" section. https://github.com/PHPOffice/PHPExcel/tree/develop/Tests Use those and piece together what you need.

Should I be using some sort of database?

In an attempt to redesign a website, I put this page together by hand. However, there are currently over 100 more shows already that need to be added, and three new shows get added every year.
In the old system, a text document was used as a makeshift 'database'; it stored data about each show, with shows separated by '#' and data fields separated with ']'. Here's an excerpt:
#The Whorl of the Leaves]WhorlOfTheLeaves]3]F]167
#Aladdin]Aladdin]8]N]0
#A Christmas Carol]XmasCarol84-]7]N]0
#The Feral Child]FeralChild]7]N]118
#Camelot]Camelot]11]N]169
A PHP script was then used to extract the information about each show and make the page seen here.
I'm sure a script could be used to put together a page such as the one shown above, but it seems like there should be a better system than a text document to store the information.
My question is: if the text document 'database' is working, should I bother changing it? Is there a better way to organize the information about each show?
SQLite would be prefect for you. It's a tiny database that requires no configuration or setup - yet comes built into most PHP installs.
Just use PDO and your good.
$db = new PDO('sqlite:/path/to/here/mydb.sq3');
$db->query('SELECT * FROM shows');
Yep, there are a ton of "better" ways of doing this. But if you're happy with it and it works, why change it?
You could save yourself a lot of trouble by using a content management system such as drupal.

Categories