Error: mysql_num_rows() expects parameter 1 to be resource

I was trying to pull some values from Database using PHP. My DB is MySQL. Suddenly I found the error: mysql_num_rows() expects parameter 1 to be resource, boolean given in I was trying to find out the problem. I went through the forum post in Daniweb after googling Finally I fixed it. What was TROLLING is just a [ ‘ ‘ ] sign My query … Continue reading Error: mysql_num_rows() expects parameter 1 to be resource

A wonderful Calendar for picking date in PHP Input/Update forms

I was writing PHP scripts the other day where I needed a calendar to pick dates. My user needs to pick date of any month or year. Problem was — Manual input of dates are tiresome and inefficient. On the other hand, if inputs are in string, I need to convert them to “datetime” as my datatype is such in the MySQL DB.

I found a wonderful Calendar a website. He made it in javascript and works very well. There are several layouts in the calendar from which developers can choose anyone. The more important thing is, you just need to pass the PHP variable which will store into the DB. You can have this Javascript Calendar from downloading from this link .

This code segment is for taking input and inserting into database

/*include this section*/
<?php require_once('calendar/classes/tc_calendar.php'); ?>

<!-- calender js link-->
<script language="javascript" src="calendar/calendar.js"></script>
<!-- finished-->
<?php
	  $myCalendar = new tc_calendar("date5", true, false); //date5 is similar to the column name of DB 
	  $myCalendar->setIcon("calendar/images/iconCalendar.gif");
	  $myCalendar->setDate(date('d'), date('m'), date('Y'));
	  $myCalendar->setPath("calendar/");
	  $myCalendar->setYearInterval(2000, 2015);
	  $myCalendar->dateAllow('2008-05-13', '2015-03-01');
	  $myCalendar->setDateFormat('j F Y');
	  $myCalendar->setAlignment('left', 'bottom');
	  $myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year');
	  $myCalendar->setSpecificDate(array("2011-04-10", "2011-04-14"), 0, 'month');
	  $myCalendar->setSpecificDate(array("2011-06-01"), 0, '');
	  $myCalendar->writeScript();
	  ?>

Continue reading “A wonderful Calendar for picking date in PHP Input/Update forms”

Insert, Update, Delete in PHP using Dreamweaver CS5

Adding data to database using input in Forms

We often need to insert data into database. We use forms to post the Data. This process is often lengthy and tiresome. You can easily insert data to Database Using Dreamweaver with almost no hand coding. If you are already familiar with DreamweaverCS5, just need to follow the steps below:

  • Insert a form
  • You can use tables to show the labels and Text fields and Lists for input
  • If you want to use a list Dynamic (that will show data in list items fetching somewhere from database), you need to do 2 things:

Continue reading “Insert, Update, Delete in PHP using Dreamweaver CS5”

solving error ”duplicate entry 0 for the key primary”

I faced this problem while tried to post data in the database. It occurred because the Table had the Primary key as ID which was ”Default 0” and not even ”auto incremented”… for testing purpose in localhost, I just made it auto-increment and ”default” to ”none”. But this is not always a solution for a database may be. the following links might help if it … Continue reading solving error ”duplicate entry 0 for the key primary”

Fetching data from DB and comparing by putting them in Arrays

I had been trying to fetch some data from DB and do soem operations on them. The operation was to find the missing values that was expected to me. I have some values in DB that are multiples of 100 but not all the numbers — there are few missing. I need those missing numbers. The output will be the list of numbers that are missing between first and last number. Thanks to Pollob for his kind help to write this script.

Functions used:
array_diff()

Continue reading “Fetching data from DB and comparing by putting them in Arrays”

Fetching Column Items from DB and Creating Hyperlink in PHP

I was trying to write a script on php that will be something like the moving bar of the ‘news websites’ where headlines are available. I did it, and here it goes for making it available for those people who needs it in future around the globe 😀 (sounds its poor work to shout, isn’t? LOL I know!) 😉

Let, I have a database named “news” and I want to show the news headlines in a box of the website like under the header. now, I have a table named “table_news”. I need to show the titles (headlines) of the news in descending order. moreover, I want that that when I will link on it, I will go to that specific news. So, a hyper link is needed to set on that HEADLINE thing.

In my case, the ID is a column and unique, auto-incremented. and the link of the respective news is like site.com/postid=ID. So I need to fetch the ID from the db and to set the HEADLINE’s ID on the text of the moving bar.
Continue reading “Fetching Column Items from DB and Creating Hyperlink in PHP”

Prolog program to traverse a list

Traverse a list: domains namelist = name* name = symbol predicates traverse(namelist) clauses traverse([]). traverse([Head|Tail]):- write(Head),nl, traverse(Tail). Also try with: domains namelist=symbol* predicates member(symbol,namelist) club_member(symbol) clauses member(X,[X|_]). member(X,[_|Tail]):- member(X,Tail). club_member(Name):- member(Name,[a,b,c,d,e]). Continue reading Prolog program to traverse a list

Prolog program to find minimum and maximum

Find out the MAXIMUM and MINIMUM values among three numbers: domains predicates max(integer,integer,integer) min(integer,integer,integer) maxmin(integer,integer,integer) clauses max(A,B,C):- A>B, A>C, write(A). max(A,B,C):- A>B, write(C). max(_,B,C):- B>C, write(B). max(_,_,C):- write(C). min(A,B,C):- A<B, A<C, write(A). min(A,B,C):- A<B, write(C). min(_,B,C):- B<C, write(B). min(_,_,C):- write(C). maxmin(A,B,C):- max(A,B,C), min(A,B,C). Continue reading Prolog program to find minimum and maximum